user2247326
user2247326

Reputation: 173

How to delete file in a dir using php script

I want to delete an image inside my profile_images folder. I tried

unlink(base_url() . "_profile_images/912aea1dd8144e07894f788978b917d3.jpg");

and an error occured

A PHP Error was encountered

Severity: Warning

Message: unlink() [function.unlink]: http does not allow unlinking

Filename: controllers/controller.php

Line Number: 100

I used codeigniter to implement this action. Is there another way to delete file?

Upvotes: 0

Views: 152

Answers (2)

DanielGaffey
DanielGaffey

Reputation: 107

You will want to use the actual filesystem reference on your server and not the URL ... so

unlink('/var/www/image_folder/file.jpg');

The parameter being the location of your file.

Upvotes: 0

francisco.preller
francisco.preller

Reputation: 6629

You are attempting to delete a URL string, you should get php to get you the full path and filename to the file to be able to unlink it.

Not sure what your path is, but PHP has several functions which should help you get the full directory path to the file.

$_SERVER['DOCUMENT_ROOT']; // Will get you PHP's document root, it's a good start.

Upvotes: 2

Related Questions