By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

unlink not working

P: n/a
I'm a newbie to php. I am trying to delete a file from the server that I put
there (one file, not the whole directory). I am using unlink ($filename);

I did the path as a relative path as follows:
.../images/6/image_001.JPG

I did a scandir
$files = scandir("../images/6");

The print_r ($files); shows that the file is one of the files present.

On the possibility that it's a protection problem (though it shouldn't be,
as I put it there in the first place), I did a
chmod($filename, "777");

The file doesn't delete from the server. Any ideas?

Thanks!
Aug 15 '08 #1
Share this Question
Share on Google+
11 Replies


P: n/a

"byteoart" <in**@byteoart.comwrote in message
news:Dc******************************@giganews.com ...
I'm a newbie to php. I am trying to delete a file from the server that I
put there (one file, not the whole directory). I am using unlink
($filename);

I did the path as a relative path as follows:
../images/6/image_001.JPG

I did a scandir
$files = scandir("../images/6");

The print_r ($files); shows that the file is one of the files present.

On the possibility that it's a protection problem (though it shouldn't be,
as I put it there in the first place), I did a
chmod($filename, "777");

The file doesn't delete from the server. Any ideas?

Thanks!
One more thing that I forgot. If I do a var_dump(is_file($filename)); it
returns false, however using FTP, I see that the file is there, and another
page accesses it and brings it up, so it definitely is there.
Aug 15 '08 #2

P: n/a
..oO(byteoart)
>I'm a newbie to php. I am trying to delete a file from the server that I put
there (one file, not the whole directory). I am using unlink ($filename);

I did the path as a relative path as follows:
../images/6/image_001.JPG

I did a scandir
$files = scandir("../images/6");

The print_r ($files); shows that the file is one of the files present.

On the possibility that it's a protection problem (though it shouldn't be,
as I put it there in the first place), I did a
chmod($filename, "777");
777 is a really bad idea. It makes the file writable for all people with
access to the server.
>The file doesn't delete from the server. Any ideas?
Any error messages? Is error_reporting set to at least E_ALL and
display_errors enabled?

Micha
Aug 15 '08 #3

P: n/a

"Michael Fesser" <ne*****@gmx.dewrote in message
news:av********************************@4ax.com...
.oO(byteoart)
>>I'm a newbie to php. I am trying to delete a file from the server that I
put
there (one file, not the whole directory). I am using unlink ($filename);

I did the path as a relative path as follows:
../images/6/image_001.JPG

I did a scandir
$files = scandir("../images/6");

The print_r ($files); shows that the file is one of the files present.

On the possibility that it's a protection problem (though it shouldn't be,
as I put it there in the first place), I did a
chmod($filename, "777");

777 is a really bad idea. It makes the file writable for all people with
access to the server.
I did that immediately before doing the unlink, so that shouldn't be a
problem.
>
>>The file doesn't delete from the server. Any ideas?

Any error messages? Is error_reporting set to at least E_ALL and
display_errors enabled?
There were no error messages, but I don't have error_reporting set. I will.

BTW, the is_file being false was operator error. It returns true. It was
during a couple of trials that it was looking at something else I
misinterpreted it. So, the is_file says it is there, but the unlink doesn't
delete it.

>
Micha

Aug 15 '08 #4

P: n/a
..oO(byteoart)
>"Michael Fesser" <ne*****@gmx.dewrote in message
news:av********************************@4ax.com.. .
>>
Any error messages? Is error_reporting set to at least E_ALL and
display_errors enabled?

There were no error messages, but I don't have error_reporting set. I will.
On a development machine this should be done in the php.ini. The correct
values are

error_reporting = E_ALL|E_STRICT
display_errors = 1

Then check again if you get an error message on the unlink() call.

Micha
Aug 15 '08 #5

P: n/a

"Jensen Somers" <je****@sig.see.invalidwrote in message
news:Zc******************************@giganews.com ...
byteoart wrote:
>"byteoart" <in**@byteoart.comwrote in message
news:Dc******************************@giganews.co m...
>>I'm a newbie to php. I am trying to delete a file from the server that I
put there (one file, not the whole directory). I am using unlink
($filename);

I did the path as a relative path as follows:
../images/6/image_001.JPG

I did a scandir
$files = scandir("../images/6");

The print_r ($files); shows that the file is one of the files present.

On the possibility that it's a protection problem (though it shouldn't
be, as I put it there in the first place), I did a
chmod($filename, "777");

The file doesn't delete from the server. Any ideas?

Thanks!
One more thing that I forgot. If I do a var_dump(is_file($filename)); it
returns false, however using FTP, I see that the file is there, and
another
page accesses it and brings it up, so it definitely is there.

It is possible this is caused by using a relative path to the file you
want to delete. Try using the full path. Using some globals you can
quickly find the root path of your web server and start from there.
I tried $path = dirname(__FILE__) . '/../images/6/image_001.JPG

aand it still didn't delete.
Aug 15 '08 #6

P: n/a

"Michael Fesser" <ne*****@gmx.dewrote in message
news:25********************************@4ax.com...
.oO(byteoart)
>>"Michael Fesser" <ne*****@gmx.dewrote in message
news:av********************************@4ax.com. ..
>>>
Any error messages? Is error_reporting set to at least E_ALL and
display_errors enabled?

There were no error messages, but I don't have error_reporting set. I
will.

On a development machine this should be done in the php.ini. The correct
values are

error_reporting = E_ALL|E_STRICT
display_errors = 1

Then check again if you get an error message on the unlink() call.
I don't have access to the server's php.ini. the hosting company has that
controlled.
Aug 15 '08 #7

P: n/a

"Jensen Somers" <je****@sig.see.invalidwrote in message
news:Zc******************************@giganews.com ...
byteoart wrote:
>"byteoart" <in**@byteoart.comwrote in message
news:Dc******************************@giganews.co m...
>>I'm a newbie to php. I am trying to delete a file from the server that I
put there (one file, not the whole directory). I am using unlink
($filename);

I did the path as a relative path as follows:
../images/6/image_001.JPG

I did a scandir
$files = scandir("../images/6");

The print_r ($files); shows that the file is one of the files present.

On the possibility that it's a protection problem (though it shouldn't
be, as I put it there in the first place), I did a
chmod($filename, "777");

The file doesn't delete from the server. Any ideas?

Thanks!
One more thing that I forgot. If I do a var_dump(is_file($filename)); it
returns false, however using FTP, I see that the file is there, and
another
page accesses it and brings it up, so it definitely is there.

It is possible this is caused by using a relative path to the file you
want to delete. Try using the full path. Using some globals you can
quickly find the root path of your web server and start from there.
I tried $path = dirname(__FILE__) . '/../images/6/image_001.JPG

aand it still didn't delete.
Aug 15 '08 #8

P: n/a

"Michael Fesser" <ne*****@gmx.dewrote in message
news:av********************************@4ax.com...
.oO(byteoart)
>>I'm a newbie to php. I am trying to delete a file from the server that I
put
there (one file, not the whole directory). I am using unlink ($filename);

I did the path as a relative path as follows:
../images/6/image_001.JPG

I did a scandir
$files = scandir("../images/6");

The print_r ($files); shows that the file is one of the files present.

On the possibility that it's a protection problem (though it shouldn't be,
as I put it there in the first place), I did a
chmod($filename, "777");

777 is a really bad idea. It makes the file writable for all people with
access to the server.
>>The file doesn't delete from the server. Any ideas?

Any error messages? Is error_reporting set to at least E_ALL and
display_errors enabled?
I put in error_reporting(E_ALL). I tried uploading another file (which I
intended to delete). I got the following error message:

Warning: move_uploaded_file() [function.move-uploaded-file]: open_basedir
restriction in effect. File(C:\WINDOWS\TEMP\php63.tmp) is not within the
allowed path(s):

However, using ftp, I can see that the file is there where it belongs and
the picture displays on the next page after the upload.

I then tried to delete the file and got this error message:

Warning: unlink(../images/6/image_007.JPG) [function.unlink]: Permission
denied

So, now I have three questions:
1 - Why did I get the error message on upload, yet it uploaded?
2 - Why didn't I get an error on chmod which appears immediately beofre the
unlink on which I got an error?
3 - Why did I get a permission denied problem for a file that I just put up
there/
Aug 15 '08 #9

P: n/a
byteoart wrote:
"Michael Fesser" <ne*****@gmx.dewrote in message
news:25********************************@4ax.com...
>.oO(byteoart)
>>"Michael Fesser" <ne*****@gmx.dewrote in message
news:av********************************@4ax.com. ..
Any error messages? Is error_reporting set to at least E_ALL and
display_errors enabled?
There were no error messages, but I don't have error_reporting set. I
will.
On a development machine this should be done in the php.ini. The correct
values are

error_reporting = E_ALL|E_STRICT
display_errors = 1

Then check again if you get an error message on the unlink() call.

I don't have access to the server's php.ini. the hosting company has that
controlled.
Then try this at the top of your script:
ini_set('display_errors','1');
ini_set('display_startup_errors','1');
error_reporting (E_ALL);

And try referencing the file with something like
$_SERVER['DOCUMENT_ROOT'] . '/images/6/image_001.JPG';

Jeff
>
Aug 15 '08 #10

P: n/a
3 - Why did I get a permission denied problem for a file that I just put
up
there/
What is the permission of the directory?

Simon

Aug 16 '08 #11

P: n/a
Simon wrote:
>
>3 - Why did I get a permission denied problem for a file that I just
put up
there/

What is the permission of the directory?

Simon
Wasnt it on a windwns p[latform?

I thoufght te rule there was that allduiercetories are only accessible
to microsoft and malware/viruses, and are totally inaccessible to free
software and the users?

:-) :-)
Aug 16 '08 #12

This discussion thread is closed

Replies have been disabled for this discussion.