Whenever I try to delete a file from my cpanel folder from my webpage using this code
$oldFile = @mysql_result(mysql_query("SELECT SUBSTR(`materialLink`, 27) FROM `documents` WHERE `iddocuments` = '$iddoc'"),0, `materialLink`);
$chmod = "0777";
chmod($oldFile,octdec($chmod));
$oldFile = 'https://www.edutopia.co.ke'.$oldFile;
if(isset($_POST['Fild'])){
$msg1 = '<script type="text/javascript">alert("File successfully deleted");</script>';
$msg2 = '<script type="text/javascript>alert("There was an error deleting that file.");</script>"';
$tFile= $_POST['Fild'];
$delFile = "DELETE FROM `documents` WHERE `iddocuments`='$tFile'";
mysql_query($delFile);
unlink($oldFile);
if (mysql_query($delFile)){
echo $msg1;
}
else {
echo $msg2;
}
}
I get the following error:
PHP Warning: chmod(): No such file or directory in /home/edutopia/public_html/fDelete.php on line 8
PHP Warning: unlink(): Unable to locate stream wrapper in /home/edutopia/public_html/fDelete.php on line 20
Could anyone be in a position to figure out the remedy, please?
2
Answers
Most likely this has to do something with paths as PHP understands them. If you SSH into the box and do:
…does it exist?
Also, check your web root. It might not be
public_html
.If
$oldFile
refers to a remote file, as perchmod()
documentation, it will not work:Source: http://php.net/manual/en/function.chmod.php