【发布时间】:2014-03-26 18:33:27
【问题描述】:
我正在尝试使此链接正常工作:
<a href='{$_SERVER['PHP_SELF']}?del=true&product_code=".($row['product_code'])."' style='color:black;' onclick='return show_confirm();'>Delete</a>
它使用 while 函数从 MSSQL 表中删除指定的行。目前,底部代码可以正常工作,因为它从 MSSQL 表中删除了特定行,但我希望它还取消链接 img 文件夹中的一个文件和 specsheets 文件夹中的另一个文件。
从img 取消链接的文件的文件名存储在该表行的product_img_name 列中,另一个文件的文件名存储在specsheet 列中。每个表行都有这两列,其中包含来自位于 img 和 specsheets 文件夹中的文件的唯一文件名。
到目前为止,当我点击删除时,我收到了这些错误:
Warning: mssql_query() [function.mssql-query]: message: Conversion failed when converting the varchar value 'G1013' to data type int. (severity 16) in D:\Hosting\dl\partscatalogue\partscataloguemanagement.php on line 1175
Warning: mssql_query() [function.mssql-query]: Query failed in D:\Hosting\dtscatalogue\partscataloguemanagement.php on line 1175
Warning: mssql_fetch_array(): supplied argument is not a valid MS SQL-result resource in D:\Hostingdtml\partscatalogue\partscataloguemanagement.php on line 1175
Warning: unlink(img/) [function.unlink]: Permission denied in D:\Hostingdml\partscatalogue\partscataloguemanagement.php on line 1177
Warning: mssql_query() [function.mssql-query]: message: Conversion failed when converting the varchar value 'G1013' to data type int. (severity 16) in D:\Hostingdml\partscatalogue\partscataloguemanagement.php on line 1179
Warning: mssql_query() [function.mssql-query]: Query failed in D:\Hostindhtml\partscatalogue\partscataloguemanagement.php on line 1179
Warning: mssql_fetch_array(): supplied argument is not a valid MS SQL-result resource in D:\Hosting\dhtml\partscatalogue\partscataloguemanagement.php on line 1179
简单来说,我的问题是,当表格行被删除时,我网站的img 文件夹中该行的文件和我网站的specsheets 文件夹中该行的文件仍然存在,不会随该行一起被删除.
这是针对特定行点击删除链接的代码:
// delete from table
if ($_GET['del'] == 'true') {
// cast id as int for security
$product_code = $_GET['product_code'];
$fileas = mssql_fetch_array(mssql_query("select product_img_name from products where product_code = $product_code"));
if (file_exists("img/$fileas")) {
unlink("img/$fileas");
}
$file38 = mssql_fetch_array(mssql_query("select specsheet from products where product_code = $product_code"));
if (file_exists("spechsheets/$file38")) {
unlink("specsheets/$file38");
}
// delete row from table
$sql = "DELETE FROM products WHERE product_code = '$product_code'";
$result = mssql_query($sql, $conn) or die();
} // end if del
感谢您的帮助。非常感谢所有帮助。
【问题讨论】:
-
if (file_exists($fileas)) {unlink("img/$fileas"); }-- 你正在检查一个路径,然后取消链接一个完全不同的路径..$fileas!==img/$fileas -
还可以查看 php.net 上的一些 comments 关于函数
unlink的内容。 unlink 函数可能没有按照您的想法执行。此外,unlink函数在成功时返回 True,在失败时返回 False;您可以在删除 MySQL 中的条目之前检查 unlink 是否可以作为检查 -
我已经更新了我的问题并更新了您在上面陈述的代码。
标签: php sql sql-server unlink