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

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

Post Reply
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

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

Post 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..
Last edited by Calimero on Tue Jun 15, 2004 5:30 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

do you have register globals on?
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

NO because of security

Post by Calimero »

Can this be done without REGISTER_GLOBALS ???
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yes.. print_r($_FILES['img1']) for your particulars...
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

Where do I put that piece of code

Post 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 ?
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Where do you think it would need to go?
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

Hey you play a quizz with a newbie :(

Post by Calimero »

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 »

well, just try it some where
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post 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"])
}
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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']);

?>
Post Reply