Forum Moderators: coopster
I want to be able to test it locally on my computer. I have Apache HTTP Server 2.0.48, PHP 4.3.4 and MySql installed and they work fine with all other PHP scripts I have. But I'm unable to "upload" locally in my computer.
The code would be the following: (an excerpt)
$name = $HTTP_POST_FILES['userfile']['name']; echo "name = $name <br>\n";
$name = $HTTP_POST_FILES['userfile']['tmp_name']; echo "Temp_name = $name <br>\n";
$name = $HTTP_POST_FILES['userfile']['type']; echo "Type = $name <br>\n";
$name = $HTTP_POST_FILES['userfile']['size']; echo "Size = $name <br>\n";
if (!is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {
$error = "You did not upload a file!<br>\n";
echo $error;
unlink ($HTTP_POST_FILES['userfile']['tmp_name']);
} else {
echo "Upload was successful<br>\n";
$locfile = "/www/htdocs/v054673/Contest/".$HTPP_POST_FILES['userfile']['name'];
copy($HTTP_POST_FILES['userfile']['tmp_name'], $locfile);
..................
..................
---------------------------------------
in the browser window I get this:
Name = 19 Cathedral - Dom.jpg
Temp_Name = C:\Website\root\tmp\phpD14.tmp
Type = image/jpeg
Size = 102420
Upload was successful
Picture upload successful!
You uploaded this image:
--------------------------------------
amd the relevant settings in php.ini are:
;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;
; Whether to allow HTTP file uploads.
file_uploads = On
; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
upload_tmp_dir = C:\Website\root\tmp
; Maximum allowed size for uploaded files.
upload_max_filesize = 2M
---------------------------------------------------
where C:\Website\root is the root directory where I keep the local copy of my site.
Now the problem is that when I upload nothing is stored in C:\Website\root\tmp
What can I do?
C:\Website\root\tmp\phpD14.tmp
so you should not see the file there ever.
Did the file copy to:
"/www/htdocs/v054673/Contest/".$HTPP_POST_FILES['userfile']['name'];
If it did then everything worked as it should. If it did not copy then try a full path name and change the spelling error on '$HTPP_POST_FILES' to '$HTTP_POST_FILES' if it's that way in the code.
Something like this:
"c:/www/htdocs/v054673/Contest/".$HTTP_POST_FILES['userfile']['name'];
JAG
I'm impressed. You spotted all errors and it works now.
The only thing is that the line
$locfile = "/www/htdocs/v054673/Contest/".$HTTP_POST_FILES['userfile']['name'];
needs to be changed to
$locfile = "C:\\Website\\root\\Contest".$HTTP_POST_FILES['userfile']['name'];
i.e. the character "\" escaped. Basically the PHP script here uses the Windows director naming convention.