Jump to content


Photo

Handle 2 file uploads at the same time.


  • Please log in to reply
6 replies to this topic

#1 Lessur

Lessur
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 21 July 2006 - 03:34 PM

Ok, I have this code:

upload.php:

$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"> 


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?

#2 spyke01

spyke01
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts

Posted 21 July 2006 - 03:47 PM

this is one of the problem
$filename=rand(500,2000).$_FILES['file']['name'];
$small_image=rand(500,2000).$_FILES['file']['name'];
should be
$filename=rand(500,2000).$_FILES['file']['name'];
$small_image=rand(500,2000).$_FILES['small_image']['name'];

because of the name on the input field

[a href="http://www.fasttracksites.com" target="_blank"]Cheap PHP Hosting[/a]

#3 Lessur

Lessur
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 21 July 2006 - 04:04 PM

Ok, I fixed that and did this:

$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>");

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

#4 Lessur

Lessur
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 21 July 2006 - 11:08 PM

hmmn....

#5 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 21 July 2006 - 11:09 PM

try to print out $_FILES['small_image']['error']. see what the error code is. maybe the file exceeded the upload max filesize.
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#6 Lessur

Lessur
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 06 August 2006 - 04:34 PM

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:

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

Help?

#7 Lessur

Lessur
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 06 August 2006 - 04:57 PM

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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users