skip to Main Content

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


  1. Most likely this has to do something with paths as PHP understands them. If you SSH into the box and do:

    ls -l /home/edutopia/public_html/fDelete.php
    

    …does it exist?

    Also, check your web root. It might not be public_html.

    Login or Signup to reply.
  2. If $oldFile refers to a remote file, as per chmod() documentation, it will not work:

    Note: This function will not work on remote files as the file to be examined must be accessible via the server’s filesystem.

    Source: http://php.net/manual/en/function.chmod.php

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search