Page 1 of 1
[SOLVED]Strange behaviour with uploading file through a form
Posted: Fri Mar 09, 2007 8:47 am
by impulse()
I have a basic form from the code:
Code: Select all
<form enctype = 'multipart/form-data'>
<input type = 'file' name = 'upload'>
<input type = 'submit' value = 'Upload'>
</form>
And if I print_r the FILES superglobal it shows all the details, including the temp directory of where the file is on the server, in this case /var/tmp. Now if I try to edit the file that has been uploaded it's not there, and if I try to send it as an e-mail attachment, it's not there either. My latest example shows that the file is at '/var/tmp/phpYT4k4u', but it's not correct. If I do 'ls -l' in the /var/tmp directory there are only 2 files that are prefixed with 'php' and they were created months ago.
I'm not sure if this is a coding problem, or a server problem. Has anyone experienced this before?
Posted: Fri Mar 09, 2007 8:50 am
by feyd
Are you sure a garbage collector is not clearing them before you attempt to see the file(s)?
How are you attempting to edit the file(s)? How are you attempting to email the file(s)?
Posted: Fri Mar 09, 2007 8:53 am
by impulse()
I'm editing the files using ViM, I'm attempting to e-mail them using phpmailer. Even listing the directory contents for every file prefixed with 'php' in the /var/tmp directory seconds after uploading the file doesn't show any newly created files.
If I specify the path to a file that I know exists in phpmailer, that file is sent fine. THe problem seems to be with the files not being stored in /var/tmp
Posted: Fri Mar 09, 2007 8:56 am
by feyd
Are you sure the permissions have not changed?
Posted: Fri Mar 09, 2007 9:25 am
by impulse()
I see the permissions as:
drwxrwxrwt 3 root wheel 36864 Mar 9 15:22 tmp
Posted: Fri Mar 09, 2007 9:35 am
by volka
What does $_FILES say about the file size and error code of the tmp file?
Posted: Fri Mar 09, 2007 9:38 am
by impulse()
The size is correct and the error code is 0.
Posted: Fri Mar 09, 2007 9:43 am
by volka
Then I second the garbarge collector guess.
Is it your server and/or what kind of access do you have? What kind of server is it (esp. what os)?
Posted: Fri Mar 09, 2007 9:47 am
by impulse()
FreeBSD x 5.3-RELEASE FreeBSD 5.3-RELEASE #1: Fri Apr 15 14:25:37 BST 2005
I don't have root privs to the server. Is there a way to check if there is a garbage collector without having root access?
Posted: Fri Mar 09, 2007 9:53 am
by feyd
What about changing the
upload_tmp_dir directive?
Edit: to clarify, it's an PHP_INI_SYSTEM level directive, but your host may give you access to the php.ini.
At any rate, you should probably talk to your host about the garbage collection that happens in that directory.
Posted: Fri Mar 09, 2007 10:53 am
by impulse()
It seems it isn't the directory privs.
Code: Select all
if(file_exists($tName)) {
echo "File exists";
}
if (is_file($tName)) {
echo "Is file";
}
if (is_readable($tName)) {
echo "Is readable";
}
echo (filesize($tName));
All of these conditions pass and filesize returns its filesize. But if I try to move or rename the file before PHP destroys it I get:
"*WARNING*: rename(/var/tmp/phpO40N3b,/usr/local/www/data/cpp/email/crm/ste.php): No such file or directory in /usr/local/www/data/cpp/crm/email/email_new1.php on line 27
"
$tName = $_FILES['userfile']['tmp_name'];
Posted: Fri Mar 09, 2007 10:55 am
by John Cartwright
can you try move_uploaded_file() instead of rename()?
Posted: Fri Mar 09, 2007 10:57 am
by impulse()
It's took me 3 hours of getting mad to realise I must specify the filename I want to move it to in move_uploaded_file aswell as the directory
Thank you for all your help though.