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!
Hi... I am having trouble getting File Upload to work. I searched the form and I found a post that is EXACTLY the same as mine (by jim) but there were not replies to it. When I run this script, I always come up blank... I am running it as a test script before I dive into the main upload class.
And my $HTTP_POST_FILES is always blank... Any suggestions? Thanks lots
A) anything in HTTP_POST_FILES should use a single quote to name things (ex: $HTTP_POST_FILES['userfile']['tmp_name']). I am unsure if the character you have is a single quote or not (it does not look like it from this end).
B) <input type="hidden" name="MAX_FILE_SIZE" value="10000"> should go before <input type="file">
C) copy() needs the full path to the copy location
Thanks Daven for replying... to address the questions
a) Yes, i am using single quotes
b) i also put the max file size before the <input filexxxxxx> and it is still does not work (i do not think that this would matter... but i might be wrong)
c)I provided the full path and still same thing
d) i am using PHP 4.0.1
I always come up empty whenever i try to do the following
<?php
# use $HTTP_POST_FILES['userfile']['name'] rather than $HTTP_POST_FILES['userfile']['tmp_name']
if(is_uploaded_file($HTTP_POST_FILES['userfile']['name'])
?>
<?php
# yet again, the filename should be from $HTTP_POST_FILES['userfile']['name']
$file_name=$HTTP_POST_FILES['userfile']['name'];
$file_path="/full/path/to/dir/".$file_name;
copy($HTTP_POST_FILES['userfile']['tmp_name'], $file_path);
?>
I tried the script that you provided and it works very well. THANK YOU SOOOOOOOOO MUCH.
My question remains however, why it that HTTP_POST_FILES is not working and it always returns empty.
This is the 2nd thing in PHP (So Far) that i have to work around. The first one was with session_start and HTTP_SESSION_xxxx not working and i had to do a work around.
May be I am not understanding this right or maybe PHP is temperamental.
I just hate to keep working around functions that PHP docs say it works.
At any rate, Thanks a lot for your help... I will go with your solution and may be i can convince the Sys. Admin. to upgrade to the new PHP
If I am reading everything correctly, your problem came from using HTTP_POST_FILES['userfile']['tmp_name']. The tmp_name attribute only works as an internal reference for PHP. You have to use the ['name'] attribute when you are calling the file. It is not a bug in PHP, that is the way it is supposed to work. However, it took me a while to learn that when I began playing with file uploads.
Do beat your SysAdmin until he upgrades your PHP. It is worth it. *grin*
i agree with you Daven... When I started encountering those problems, I started doing "process of elimination" and started to try everything and anything.
The whole thing stems from the fact that i cannot get HTTP_POST_VARS to recognize the file name and it keep giving me a "none" for the file name.
I.E. Look at the following code that outputs the result which is after it: (I turned all errors and warnings to on)
Warning: Undefined index: none in /home/www/html/admin/test_fileupload.php on line 13
-0--
Warning: Undefined index: none in /home/www/html/admin/test_fileupload.php on line 14
-1--
Warning: Undefined index: none in /home/www/html/admin/test_fileupload.php on line 15
-2--
Warning: Undefined index: none in /home/www/html/admin/test_fileupload.php on line 16
-3--
-0a--
-1a--none
-2a--Array
-3a--Array
Warning: Undefined index: none in /home/www/html/admin/test_fileupload.php on line 23
Possible file upload attack. Filename:
Warning: Undefined index: none in /home/www/html/admin/test_fileupload.php on line 27
http_post_files:
As you can see, I keep coming up with file name of none. I was able to get it to tell me that the file name is an array. But that’s as far as I was able to take it.
Yes and the value for file_uploads is 1 for the local value and 1 for the master.
I also have safe_mode turned off, register_globals to ontrack_errors to OFF.
The problem is that no file is actually being uploaded (hence the name="" and size=0 attributes). Do you have register_globals on? You mentioned it, but did not say whether it was on or off. For HTTP_POST_FILES, register_globals must be on, or you will get nulls similar to the results you have been experiencing.