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!
Moderator: General Moderators
Calimero
Forum Contributor
Posts: 310 Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way
Post
by Calimero » Sat Jun 12, 2004 6:18 pm
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..
Last edited by
Calimero on Tue Jun 15, 2004 5:30 pm, edited 1 time in total.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Jun 12, 2004 6:39 pm
do you have register globals on?
Calimero
Forum Contributor
Posts: 310 Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way
Post
by Calimero » Tue Jun 15, 2004 3:29 am
Can this be done without REGISTER_GLOBALS ???
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jun 15, 2004 3:39 am
yes.. print_r($_FILES['img1']) for your particulars...
Calimero
Forum Contributor
Posts: 310 Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way
Post
by Calimero » Tue Jun 15, 2004 1:18 pm
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 ?
patrikG
DevNet Master
Posts: 4235 Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK
Post
by patrikG » Tue Jun 15, 2004 1:26 pm
Where do you think it would need to go?
Calimero
Forum Contributor
Posts: 310 Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way
Post
by Calimero » Tue Jun 15, 2004 1:47 pm
I realy dont know,
I quess before IF in the script.
REALY DONT KNOW, please help.
Illusionist
Forum Regular
Posts: 903 Joined: Mon Jan 12, 2004 9:32 pm
Post
by Illusionist » Tue Jun 15, 2004 1:55 pm
well, just try it some where
patrikG
DevNet Master
Posts: 4235 Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK
Post
by patrikG » Tue Jun 15, 2004 2:54 pm
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"])
}
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jun 15, 2004 3:09 pm
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']);
?>