Jump to content

Archived

This topic is now archived and is closed to further replies.

Lessur

Handle 2 file uploads at the same time.

Recommended Posts

Ok, I have this code:

upload.php:

[code]
$max_filesize = 5000000;

$max_imagesize = 20480;

$filename=rand(500,2000).$_FILES['file']['name'];

$small_image=rand(500,2000).$_FILES['file']['name'];

$smallimagepath = "/small_images";

...


elseif ($_FILES['file']['name'] == "") {

echo "Field flash file left blank <a href='?'>Go back?</a>";

}

elseif ($_FILES['file']['size'] > $max_filesize){

echo "Error! flash file must not be bigger than 5 MB  <a href='?'>Go back?</a>";

}


...


elseif(file_exists($upload.$filename)){

echo "Error! File already exists on server, rename and try again. <a href='?'>Go back?</a>";

}

elseif ($_FILES['small_image']['size'] > $max_imagesize){

echo "Error 50x50 image must not be bigger than 20k  <a href='?'>Go back?</a>";

}

elseif(file_exists($upload.$small_image)){

echo "Error! 50x50 image already exists on server, rename and try again. <a href='?'>Go back?</a>";

}

else{

$upload = dirname(__FILE__)."/uploads/";

copy($_FILES['file']['tmp_name'],$upload.$filename) or die("<br>Error! Couldn't upload file! <a href='?'>Go back?</a>");

$size=$_FILES['file']['size'];

$upload = dirname($smallimagepath)

copy($_FILES['small_image']['tmp_name'],$upload.$small_image) or die("<br>Error! Couldn't upload 50x50 Image! <a href='?'>Go back?</a>");



.....


<input type="file" name="file">

....

<input type="file" name="small_image">

[/code]

What I want this to do, is upload the file in the small_image box to directory ' small_images ' and for the ' file '  to upload to uploads.  I also want them to submit their filepath to the database.

What it is doing instaed of this is making 2 copies of ' file ' and putting 1 in both ' uploads ' and ' small images '.  It is also submitting the file path to the mysql database under both 'file' and ' small_image '


How can I stop this from happening?

Share this post


Link to post
Share on other sites
this is one of the problem
[code]
$filename=rand(500,2000).$_FILES['file']['name'];
$small_image=rand(500,2000).$_FILES['file']['name'];
[/code]
should be
[code]
$filename=rand(500,2000).$_FILES['file']['name'];
$small_image=rand(500,2000).$_FILES['small_image']['name'];
[/code]

because of the name on the input field

Share this post


Link to post
Share on other sites
Ok, I fixed that and did this:

[code]$upload2 = dirname($smallimagepath);

copy($_FILES['small_image']['tmp_name'],$upload2.$small_image) or die("<br>Error! Couldn't upload 50x50 Image! <a href='?'>Go back?</a>"); [/code]

But I am getting "Error! Couldn't upload 50x50 Image!" as an error.  Hmm.

Share this post


Link to post
Share on other sites
try to print out $_FILES['small_image']['error']. see what the error code is. maybe the file exceeded the upload max filesize.

Share this post


Link to post
Share on other sites
Ok, I have come back to this topic becasue I was out of town.  The image did not exceed the max filesize.  I still don't know how to fix this.  I have tried all the above.  But when I clikc submit I get:

"Error! Couldn't upload 50x50 Image!"

Which is this line:

[code]copy($_FILES['small_image']['tmp_name'],$upload2.$small_image) or die("<br>Error! Couldn't upload 50x50 Image! <a href='?'>Go back?</a>");[/code]

Help?

Share this post


Link to post
Share on other sites
Oh, for the reg file upload (that works)  I have this code:

$upload = dirname(__FILE__)."/uploads/";

But for the small image one I have:

$upload2 = dirname($smallimagepath);


Instead should I have:

$upload2 = dirname(__FILE__)."/small_images/";

?

Or what does __FILE__ do?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.