Page 1 of 1

[SOLVED]Upload problem, filename could be the source :)

Posted: Sat Jun 12, 2004 6:18 pm
by Calimero
Can anypne tell me what is wrong with this script, I'm trying to upload a file but, the script tells me that the name of the file is not correct - not valid. I'm hosting apache on winXP.

Input from a form:

Code: Select all

<FORM ACTION="upload.php" METHOD="POST" ENCTYPE="multipart/form-data"> 
<INPUT TYPE="file" NAME="img1">
<INPUT TYPE="submit" NAME="submit3" VALUE="Upload File">
</FORM>
<?php

if ($img1_name != "")
{
@copy("$img1" ,  "users/$img_name")

or die("Couldn't uplad your file");
}
else
{
die("No file specified");
}

?>
NOTE = the script is not mine, its free to use, so whats the problem.

Thanks ahead.


feyd enabled bbcode and fixed position of [php.] tag start..

Posted: Sat Jun 12, 2004 6:39 pm
by feyd
do you have register globals on?

NO because of security

Posted: Tue Jun 15, 2004 3:29 am
by Calimero
Can this be done without REGISTER_GLOBALS ???

Posted: Tue Jun 15, 2004 3:39 am
by feyd
yes.. print_r($_FILES['img1']) for your particulars...

Where do I put that piece of code

Posted: Tue Jun 15, 2004 1:18 pm
by Calimero
Where do I put that piece of code in the above script, and can I just duplicate the input field (file) and by one submit the script should upload both or as many as I want files - Thats the idea.
Can this be done ?

Posted: Tue Jun 15, 2004 1:26 pm
by patrikG
Where do you think it would need to go?

Hey you play a quizz with a newbie :(

Posted: Tue Jun 15, 2004 1:47 pm
by Calimero
I realy dont know,
I quess before IF in the script.
REALY DONT KNOW, please help.

Posted: Tue Jun 15, 2004 1:55 pm
by Illusionist
well, just try it some where

Posted: Tue Jun 15, 2004 2:54 pm
by patrikG
Your code:

Code: Select all

<?php
if ($img1_name != "")
{
@copy("$img1" ,  "users/$img_name")
}
?>

$_FILES is a superglobal like $_SERVER - have a look in the manual under "predefined variables" and "file upload".


Try instead:

Code: Select all

<?php
if (!empty($_FILES["img1_name"])){
copy($_FILES["img"] ,  "users/".$_FILES["img1_name"])
}
?>

Posted: Tue Jun 15, 2004 3:09 pm
by feyd
more like this

Code: Select all

<?php

if(!empty($_FILES) && $_FILES['img1']['size'] < 200000 /* max size */ && $_FILES['img1']['size'] > 0)
  move_uploaded_file($_FILES['img1']['tmp_name'], '/path/to/new/location/'.$_FILES['img1']['name']);

?>