Simple PHP File Upload Help - Where did the file go?

her209

No Lifer
Oct 11, 2000
56,336
11
0
I'm following the tutorial found here, however, after I upload the jpg, I don't see where the file went. I looked for an upload folder on the entire filesystem and do not see an upload folder whatsoever. I've tried creating one under the /tmp folder and under the /var/www/html folder with the same result. I've tried chmod'ing the upload folder to allow everyone to write as well.

I'm using CentOS 4.8 w/ Apache 2.0.52 and PHP 4.3.9.
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,695
4,658
75
You did see this bit, didn't you:
The temporary copied files disappears when the script ends. To store the uploaded file we need to copy it to a different location:
 

theknight571

Platinum Member
Mar 23, 2001
2,896
2
81
IIRC... The file is initially uploaded to the server's default Temp directory.

The move_uploaded_file is then used to move it to where you want.

Looking at the code, it appears that the "upload" directory would need to be created in the directory your php page is in.... i.e. a subdirectory of the current directory.

example:

htdocs\mysite\uploadscript.php
htdocs\mysite\upload\uploaded_files_moved_to_here.jpg

It's been awhile since I last wrote a script to upload a file, so I might be off. :)
 

her209

No Lifer
Oct 11, 2000
56,336
11
0
IIRC... The file is initially uploaded to the server's default Temp directory.

The move_uploaded_file is then used to move it to where you want.

Looking at the code, it appears that the "upload" directory would need to be created in the directory your php page is in.... i.e. a subdirectory of the current directory.

It's been awhile since I last wrote a script to upload a file, so I might be off. :)
I created an upload directory in the /var/www/html where the upload.htm and upload_file.php files are also located. No go. I've tried explicitly setting the temporary upload folder in the /etc/php.ini configuration file without success also.
 

theknight571

Platinum Member
Mar 23, 2001
2,896
2
81
Hmmm...

Does the upload have the proper rights set? (Just asking... kinda like... "Is it plugged in?" :))

I recreated the files as published... no changes at all.

When you submit the file do you get the "success" output:

Example:
Upload: document-small.gif
Type: image/gif
Size: 1.330078125 Kb
Temp file: C:\WINDOWS\TEMP\php1BE.tmp
Stored in: upload/document-small.gif

I'm about to head home, but I will check in a little later to see if you were able to figure it out.
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,695
4,658
75
Since you're on Linux or something, try this:

  1. Open a terminal to the directory where you wanted to upload ("upload").
  2. Type "sudo -u www-data touch temp.txt"
  3. Enter your sudo password (i.e. your admin/root password.)
  4. Type "ls -l temp.txt". The file should be there, and owned by www-data.

If you get a "no such user" error, you have a different Apache user.
If you get a "Permission denied" error, that replicates your problem. In that case I'd make sure all the parent directories allowed writing by www-data.
If you get no error...I don't know what's wrong. :hmm:
 

her209

No Lifer
Oct 11, 2000
56,336
11
0
Since you're on Linux or something, try this:

  1. Open a terminal to the directory where you wanted to upload ("upload").
  2. Type "sudo -u www-data touch temp.txt"
  3. Enter your sudo password (i.e. your admin/root password.)
  4. Type "ls -l temp.txt". The file should be there, and owned by www-data.

If you get a "no such user" error, you have a different Apache user.
If you get a "Permission denied" error, that replicates your problem. In that case I'd make sure all the parent directories allowed writing by www-data.
If you get no error...I don't know what's wrong. :hmm:
I got it working. Here's what I did.

1. Created the upload folder in the same folder as the upload_file.php file.
2. Chmod'd the upload folder with 766.
3. Ran the instructions you posted, substituting apache for www-data. Result was a Permission denied.
4. Chown'ed the upload folder with the apache user.
5. Reran the instruction you posted. Result was the creation of the temp.txt
6. The PHP file upload worked.

One last question, is the permission setting on the file supposed to be read/writeable by owner and no one else, i.e. -rw-------?