File Upload pblm with tmp_name

Alles, was PHP betrifft, kann hier besprochen werden.

File Upload pblm with tmp_name

Postby mickeymouse » 16. March 2012 22:05

My objective is to have the user upload a file by specifying the path & file name in a form.
Entering & verification of the entry works perfectly.
The upload to the temporary location seems to work but not the copy of this upload to it's final destination.

My code is:

//================UPLOAD FILE TO TEMP PLACE====================

if ($_FILES["filenm"]["error"] > 0)
{echo "Error: " . $_FILES["filenm"]["error"] . "<br />";}
else{echo "Upload: " . $_FILES["filenm"]["name"] . "<br />";
echo "Type: " . $_FILES["filenm"]["type"] . "<br />";
echo "Size: " . ($_FILES["filenm"]["size"] / 4096) . " Kb<br />";
echo "Stored in: " . $_FILES["filenm"]["tmp_name"];} <--------------line 38
//=====================================================================


//=====================Upload Restrictions ===========================

if ((($_FILES["filenm"]["type"] == "image/gif")
|| ($_FILES["filenm"]["type"] == "image/jpg")
|| ($_FILES["filenm"]["type"] == "image/jpeg")
|| ($_FILES["filenm"]["type"] == "image/pjpeg"))
&& ($_FILES["filenm"]["size"] < 10000000))
{if ($_FILES["filenm"]["error"] > 0)
{echo "Error: " . $_FILES["filenm"]["error"] . "<br />";}
else{echo "Upload: " . $_FILES["filenm"]["name"] . "<br />";
echo "Type: " . $_FILES["filenm"]["type"] . "<br />";
echo "Size: " . ($_FILES["filenm"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["filenm"]["tmp_name"];}}
else{echo "Invalid file";}
//=======================================================================


//=================Move Temp File to Final Place=========================

if (file_exists("upload/" . $_FILES["filenm"]["name"]))
{echo $_FILES["filenm"]["name"] . " already exists. ";}
else{move_uploaded_file($_FILES["filenm"]["tmp_name"],
"upload/".$_FILES["filenm"]["tmp_name"]); <-------------------------------line 64
echo "Stored in: " . "upload/" . $_FILES["filenm"]["tmp_name"];}
//=========================================================================


AND THE RESULT IS:

Upload: AFP_DiNapoli.JPG
Type: image/pjpeg
Size: 502.18286132812 Kb
Stored in: C:\xampp\tmp\php7DD.tmpUpload: AFP_DiNapoli.JPG
Type: image/pjpeg
Size: 2008.7314453125 Kb
Stored in: C:\xampp\tmp\php7DD.tmp
Warning: move_uploaded_file(upload/C:\xampp\tmp\php7DD.tmp) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\xampp\htdocs\Annuaire\AF_UploadFile.php on line 64

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampp\tmp\php7DD.tmp' to 'upload/C:\xampp\tmp\php7DD.tmp' in C:\xampp\htdocs\Annuaire\AF_UploadFile.php on line 64
Stored in: upload/C:\xampp\tmp\php7DD.tmp



I DEFINED:

$tmp_name="c:\xampp\htdocs\annuaire\tmp";

AND CHANGED MY CODE FROM "tmp_name" TO "$tmp_name" AND GOT THE FOLLOWING UNSUCESSFUL RESULTS.

Upload: AFP_DiNapoli.JPG
Type: image/pjpeg
Size: 502.18286132812 Kb

Notice: Undefined index: C:\xampp\htdocs\Annuaire\tmp\ in C:\xampp\htdocs\Annuaire\AF_UploadFile.php on line 38
Stored in: Upload: AFP_DiNapoli.JPG
Type: image/pjpeg
Size: 2008.7314453125 Kb

Notice: Undefined index: C:\xampp\htdocs\Annuaire\tmp\ in C:\xampp\htdocs\Annuaire\AF_UploadFile.php on line 54
Stored in:
Notice: Undefined index: C:\xampp\htdocs\Annuaire\tmp\ in C:\xampp\htdocs\Annuaire\AF_UploadFile.php on line 63

Notice: Undefined index: C:\xampp\htdocs\Annuaire\tmp\ in C:\xampp\htdocs\Annuaire\AF_UploadFile.php on line 63

Notice: Undefined index: C:\xampp\htdocs\Annuaire\tmp\ in C:\xampp\htdocs\Annuaire\AF_UploadFile.php on line 64
Stored in: upload/

WHAT SHOULD I BE DOING?

THANKS FOR YOUR HELP.
MICKEY
mickeymouse
 
Posts: 58
Joined: 08. March 2009 06:10
Location: France & Canada
Operating System: Win 7 Family Prem Ed (64 bit?)

Re: File Upload pblm with tmp_name

Postby anselm » 20. March 2012 08:03

Hi mickeymouse,
Unable to move 'C:\xampp\tmp\php7DD.tmp' to 'upload/C:\xampp\tmp\php7DD.tmp'

upload/C:\xampp\tmp\php7DD.tmp
Wrong pathname.
move_uploaded_file($_FILES["filenm"]["tmp_name"],"upload/".$_FILES["filenm"]["tmp_name"]); <-------------------------------line 64

change
move_uploaded_file($_FILES["filenm"]["tmp_name"],$_FILES."upload/".["filenm"]["tmp_name"]);
Please test it
Best Regards
anselm
 

Re: File Upload pblm with tmp_name

Postby mickeymouse » 24. March 2012 15:20

Many thanks for your help Anselm. It seemed nobody was going to answer my post.
Unfortunately the solution didn't work.
I now get:
Parse error: syntax error, unexpected '[' in C:\xampp\htdocs\Annuaire\AF_UploadFile.php on line 68
(line 68 is this replacment code you gave me.)
I tried to figure out why and which '[' is unexpected but unsuccessful.

Looking forward to your feed back.
Mickey
mickeymouse
 
Posts: 58
Joined: 08. March 2009 06:10
Location: France & Canada
Operating System: Win 7 Family Prem Ed (64 bit?)

Re: File Upload pblm with tmp_name

Postby mickeymouse » 24. March 2012 16:19

It is now OK. I don't know if it's the best way but it works.

Early in my PHP file, I defined:
$myfilenm=$_FILES["filenm"]["name"];
and I changed the 2nd parameter of what you gave me, i.e., "$_FILES.upload/". ["filenm"]["tmp_name"] ot $myfilenm
giving me:
move_uploaded_file($_FILES["filenm"]["tmp_name"],$myfilenm);

With this the file gets uploaded to it's final destination and with the correct file name.

Again, many thanks for your help.
Mickey
mickeymouse
 
Posts: 58
Joined: 08. March 2009 06:10
Location: France & Canada
Operating System: Win 7 Family Prem Ed (64 bit?)


Return to PHP

Who is online

Users browsing this forum: No registered users and 13 guests