[SOLVED]Strange behaviour with uploading file through a form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

[SOLVED]Strange behaviour with uploading file through a form

Post 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?
Last edited by impulse() on Fri Mar 09, 2007 10:56 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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)?
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Are you sure the permissions have not changed?
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

I see the permissions as:

drwxrwxrwt 3 root wheel 36864 Mar 9 15:22 tmp
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

What does $_FILES say about the file size and error code of the tmp file?
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

The size is correct and the error code is 0.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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)?
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post 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'];
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

can you try move_uploaded_file() instead of rename()?
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post 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 :oops:

Thank you for all your help though.
Post Reply