PDA

View Full Version : Uploading Two Files


dniwebdesign
03-02-2006, 08:32 AM
$copy = copy($_FILES['imagefile']['tmp_name'], "../gallery_videos/".$_FILES['imagefile']['name']) or $error="Could not copy video file, please contact us.";
echo "<br>".$error."<br>";
if($copy)
{
return "<font color='#006600'>The video was added to the database and has been uploaded.</font>";
//Upload the Screenshot
$copy = copy($_FILES['screenfile']['tmp_name'], "../gallery_videos/".$_FILES['screenfile']['name']) or $error="Could not copy video file, please contact us.";
echo "<br>".$error."<br>";
if($copy)
{
return "<font color='#006600'>The video was added to the database and has been uploaded.</font>";
}
else
{
return "<font color='#006600'>The video was added to the database.</font><br><font color='#FF0000'>The video file was not uploaded.<br>Please make sure the file is under 8 Megabytes and if it is<br>contact the webmaster.</font>";
}
}
else
{
return "<font color='#006600'>The video was added to the database.</font><br><font color='#FF0000'>The video file was not uploaded.<br>Please make sure the file is under 8 Megabytes and if it is<br>contact the webmaster.</font>";
}

I have the above code snippet, now... I am trying to upload two files through one POST request... seems simple enough... however. <_< It uploads the first file (IE: $_FILE['imagefile'] ) but will not upload the $_FILE['screenfile'] . Why won't it work?

Yes... I know my $_FILE['screenfile'] is correct as it adds the correct URL to the database to find the file, it just won't upload the screenfile, file.

dniwebdesign
03-02-2006, 07:58 PM
Anybody have an idea?

Archangel
03-02-2006, 09:51 PM
I'm not very Savy as PHP yet so I'm just stabbing in the dark...but maybe when you're trying to upload the screen file you should use a different var instead of reusing $copy?

Maybe it doesn't like you changing the variable it's using for the if statement?

dniwebdesign
03-02-2006, 10:22 PM
I have also tried this using $copy2 as variable, as well as having the second upload for the screenfile outside of the $copy if statement. (if that makes sense).

StupidRalph
03-03-2006, 05:18 AM
Where is the rest of the code? Where is the html for the form you are using with this script? I think it is relevant. Are you trying to upload two files by just submitting the form once? If so, I think it will be best if you were to give each file input the same name that way you can have the values stored in an array. Then simply run a for loop to upload the image and repeat that process as many times as you need.

dniwebdesign
03-03-2006, 07:14 AM
Do explain in more detail the idea behind the same input name and arrays...

As you can see from the code, the names for the input values "of type file" are different. The MySQL Query works fine as does uploading the first file (imagefile)... just not the second upload (screenfile). And yes, this is from one form and one submission.

dniwebdesign
03-03-2006, 03:42 PM
:D Bumps :D

dniwebdesign
03-06-2006, 03:22 AM
:( Anybody know why this isn't working?

NickPresta
03-06-2006, 03:48 AM
Could you post the full code, please.

StupidRalph
03-07-2006, 02:34 AM
Could you post the full code, please.
My sentiments exactly.

And what I meant was if you had

<input name="uploaded_files[]" type="file" />
<input name="uploaded_files[]" type="file" />

This would create two different inputs for forms. And when you submit it would store the values of the two in an array.

You could then loop through the array which uploads the file something like this.

$uploaded_files = array();

....
foreach ($uploaded_files as $uploaded_file) {
//Do my uploading and filenaming code here.
}


But as stated earlier post ALL your code that you have. And if you have different pages just write the page name above it like so.

somepage.php

<?php
...
echo "Work your magic PHP";
?>

anotherpage.php

<?php
...
echo "This is another page's code";
?>

This way we can see first hand what your code is doing and can assist you better.

Here is a link that will help you understand about naming your form names to be understood as arrays http://www.onlamp.com/pub/a/php/2004/08/26/PHPformhandling.html

StupidRalph
03-13-2006, 03:16 AM
I just put this in an edit but then i thought about it and didn't know if that would notify you that I edited my post. So here is the link once again to help you understand about arrays.
http://www.onlamp.com/pub/a/php/2004/08/26/PHPformhandling.html