user2060451
user2060451

Reputation: 2688

PHP unlink error - path error

I am using same syntax as everyone else but... i can't get it to work.

I have tried quite a few options to unlink file from directory.

Summary: delete.php (the file that executes the action) is in the main folder. The file (image) to be deleted is under the sub-directory "upload".

$file = $name . '.' . $ext; 

$tmpfile = 'upload/'. $file; 
unlink($tmpfile);

Than this one too.

if (!unlink("upload/$file")) {
    echo "Error deleting ... $file  ... from directory";
}
else {
    echo "Deleted $file";
}

And many more. Here is the error log

unlink(upload/Glauber_3232_MAGNOLIA_ST__016.jpg) [function.unlink]: No such file or directory in /home2/braaasil/public_html/openhouse/delete.php on line 30

Therefore, I am not being able to exit the main directory (where delete.php) is and go to subdirectory "upload" where my images are. Any suggestion will be greatly appreciated.

EDIT

public_html

   openhouse (sub domain)

      delete.php (this is a file)

      upload (this is sub folder)

If this is not clear I can take a picture. delete.php and subfolder upload are on the same level, both kids of openhouse. Hope this is clear.

Upvotes: 3

Views: 11001

Answers (2)

user2060451
user2060451

Reputation: 2688

I am sorry ! For some reason, DB started to accept both image.jpg and image.JPG even though I had the command strtolower for all entries.

Images are being deleted by the very code is posted in this question. I really appreciate your time and apologize one more time.

For all others: make sure that DB, file and search all all set to lower case since DB may be upper and lower case sensitive.

Upvotes: 0

Aristona
Aristona

Reputation: 9341

Your script has no issues but I believe you're giving the wrong path to your application, so it is unable to find specified file under upload folder.

I think you're using a subfolder, but upload points to root folder, hence it can't find the folder.

Try: unlink (__DIR__ . '/upload/' . $file);

If it works, you can also use it as: "./upload/$file"

Upvotes: 4

Related Questions