473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

unlink() returns TRUE but does not delete

code green
1,726 Expert 1GB
I have this piece of code to tidy up after a function that calls move_uploaded_file()
Expand|Select|Wrap|Line Numbers
  1. if(file_exists($destination.$filename))
  2. {
  3.     $exitmsg .= 
  4.         "<br>File still in temporary location
  5.         <br>$filename
  6.         <br>Attempting deletion ";
  7.     if(unlink($destination.$filename))
  8.         $exitmsg .= '<br>Success deleting. Please try again ';
  9.     else
  10.         $exitmsg .= '<br>Failed deleting. Please inform IT';
  11.     }
Basically I am attempting to delete a file from a
move_uploaded_file() 'destination' so that the file can upload. This piece of code returns TRUE but the file is still there
Expand|Select|Wrap|Line Numbers
  1. if(unlink($destination.$filename))
I am running Apache Windows with IE which I suspect is the issue.
Or am I completely mis-understanding unlink()?
By the way it is a CSV file.
May 19 '09 #1
9 8394
Markus
6,050 Expert 4TB
Strange. You sure you've got permissions to delete it?

Furthermore, move_uploaded_file() will overwrite (I believe) the file if it already exists.
May 19 '09 #2
prabirchoudhury
162 100+
you may set up directory permission, before calling unlink().

Expand|Select|Wrap|Line Numbers
  1. chmod("$destination", 0777); 
  2.  
  3.  
May 20 '09 #3
code green
1,726 Expert 1GB
Markus
move_upload_file() is called in a static class method.
This method checks if the file is already there before moving.
It then warns the user and handles the warning cleanly.

It is after this method that I want to delete the file so the user
can try again if they are happy.

I am not getting a permissions warning as expected but will try changing.
The strange thing is, if I refresh the page the file is then deleted.
And I am physically checking the directory.

The only things I can think of are a possible racing issue or
unlink() does not work well in Windows
May 20 '09 #4
hoopy
88
I have had no problems with using unlink() with WAMP so it could be an issue with Apache I guess and its permissions. move_uploaded_file() does indeed overwrite any file of the same name. Perhaps its a problem with the class have you tried a simple test to remove the same file like:

echo unlink("Some Path Name");

And see if it returns true or false?

Its odd that it works on a refresh but not before.
May 20 '09 #5
code green
1,726 Expert 1GB
Tried prabirchoudhury's suggestion. Wow that is hard to spell!
And did
Expand|Select|Wrap|Line Numbers
  1. chmod($destination, 0777); 
I was previously using
Expand|Select|Wrap|Line Numbers
  1. chmod($destination, 0666);
No idea what the difference is.
Also re-jigged the code so that the user can take a simpler course of action,
so it could be that I have inadvertently 'stepped over' the the problem.
Seems to be working now anyway, thanks for all the help.
May 21 '09 #6
prabirchoudhury
162 100+
that sound great .. you could read more abt php chmod
May 22 '09 #7
Markus
6,050 Expert 4TB
PHP Manual: read it.


;)
May 22 '09 #8
code green
1,726 Expert 1GB
I don't see the relevance of this page http://php.net/ read it
May 26 '09 #9
Markus
6,050 Expert 4TB
@code green
Nevermind. T'were a joke.
May 26 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Eric | last post by:
Hello, I created a form to upload files. The formfield contents are stored as records in an Ascii file "data.dat"; for reasons I am not using a MySql database. The upoaded file itself is stored...
5
by: Phil Powell | last post by:
print_r(is_file("$logPath/$logFileName")); // RETURNS 1 unlink("$logPath/$logFileName"); // RETURNS WARNING: PERMISSION DENIED This code should tell me that the file located at...
4
by: rbt | last post by:
Can someone detail the differences between these two? On Windows which is preferred? Also, is it true that win32api.DeleteFile() can remove the 'special' files located in the 'special' folders...
6
by: Benjamin | last post by:
Hello, I'm running PHP 5.2.0 as a Apache 2.2 server module. When, I try to unlink I get this: "Warning: unlink(file.txt) : Permission denied..." What and how do I change this so it works? Thanks
4
by: nitinpatel1117 | last post by:
Hi I am trying to delete a csv file using the unlink() function, but i keep getting a permission denied warning Warning: unlink(UsedNOS200704191.CSV): Permission denied in...
7
by: daithimcc | last post by:
I have been trying to delete a file using a script and it is refusing to go. (I have very little experience of Perl). One script creates the temporary file (empty) and later another is to delete it....
15
by: Morteneistrom | last post by:
Im a complete n00b at PHP so please forgive me if this i a stupid question Why wont the following work. PHP Code: <?php foreach (glob('../images/profil/*.jpg') as $filename) { echo...
11
by: byteoart | last post by:
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...
18
by: Coffee Pot | last post by:
Thanks for any advice. ~ CP
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.