Jump to content

Handle 2 file uploads at the same time.


Lessur

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?
Link to comment
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
Link to comment
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.
Link to comment
Share on other sites

  • 3 weeks later...
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?
Link to comment
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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.