Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Can not delete A file on Tasks
  • Hi;

    I am trying to do a batch delete on files via task. Check if the files are delete on the db (using orm/soft). I am used to deleting files normally in non-task way and it works fine. But in task, it is giving me this error.


    Error - Cannot delete file: given path "/path/to/file/in/the/app/share/93fa7fe9ab4b7098d1f809636e64d6b6.jpg" is not a file. in COREPATH/classes/file.php on line 578

    I tried it on windows via xampp same error. I figured that it would work in linux OSes because of the difference between / and \.

    Here is my code.

    protected static function _delete_file($path)
    {
    if(file_exists($path))
    {
    print $path;
    print \Fuel\Core\File::delete($path);
    }
    }

    Also file_exist is not seeing it as a file either. So I removed it to show the error.
  • If you're on Windows, that path is incorrect, a fully qualified path should start with a drive letter, starting with a / is a linux filesystem.

    How do you construct the path?
  • Here is the part where I construct the path. The $filename is the 93fa7fe9ab4b7098d1f809636e64d6b6.jpg one.

    Path is taken in the config.

    Here is the snippet of the config file.

    'share_img_path' => DOCROOT.'assets/share/',

    public static function delete_file($filename)
    {
    $path = Fuel\Core\Config::get('share_img_path').$filename;
    Model_AppModel::_delete_file($path);
    }
  • Which means that the possible culprit is DOCROOT. Which means you have to check your index.php to make sure it uses Windows paths instead of Linux paths.
  • But I also uploaded it on lunix to test that case, it still doesn't delete the file. Also when I use the delete inside the app (Model and Controller) it is working just fine.
  • Then it might be a rights issue. When it's uploaded and written in the app, it will have the rights of your webserver user. Those may be differrent from your commandline user that runs the tasks.
  • Ok. For example, if I run php oil refine and I am on a user called developer, I am inheriting the rights for the developer?


    also, if you mean webserver user, by default, that would be apache, correct?
  • HarroHarro
    Accepted Answer
    Yes, correct, in both cases. To create an environment that gives both access, you need to do some planning.

    On our servers, we have a group www-data, both apache and all user accounts used on the commandline are member of this group. This group is assigned to all files and directories, with the sticky bit on (so new files will automatically inherit this group). Directories are created with a 770 mask, files with a 660 mask.

    This gives everyone in the group read/write access on all files, no matter who created them (i.e. who the owner of the file is).

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion