Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Need help uploading multiple files
Index -> Programming, PHP -> PHP Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Numbah51




PostPosted: Sat Nov 11, 2006 8:48 pm   Post subject: Need help uploading multiple files

I want one to be an image and one to be a wmv. here is my code:

code:

<FORM ACTION="videoadd.php" enctype="multipart/form-data" method="POST">
Title: <INPUT TYPE="text" name="Title"><BR>
Rating (/10): <INPUT TYPE="text" name="Rating"><BR>
Choose a video file to upload: <input type="file" name="file[]"><BR>
Choose an image file to upload: <input type="file" name="file[]"><BR>
<INPUT TYPE="hidden" name="UploadedBy" Value="<?PHP echo $Nickname; ?>">
<INPUT TYPE="hidden" name="Number" Value="<?PHP echo ($HighNumber+1); ?>">
<INPUT TYPE="hidden" name="Date" Value="<?PHP echo $today = date("F j, Y"); ?>">
<INPUT TYPE="hidden" name="AddFile" Value="True">
<TEXTAREA name="Description" COLS=40 ROWS=8>Write Description Here</TEXTAREA><BR><BR>
<INPUT type="submit" value="Add" style="width:100;height:40;">
</FORM>


videoadd.php:
code:

<?PHP
foreach ($_FILES["file"]["error"] as $key => $error) {
   if ($error == UPLOAD_ERR_OK) {
       $tmp_name = $_FILES["file"]["tmp_name"][$key];
       $name = $_FILES["file"]["name"][$key];
       move_uploaded_file($tmp_name, "Upload/$name");

   }
}
?>


The non-wmv file always uploads but wmv's never do. Any help would be greatly appreciated. Thanks.
Sponsor
Sponsor
Sponsor
sponsor
octopi




PostPosted: Sun Nov 12, 2006 2:50 pm   Post subject: (No subject)

Hello,

A simpler way to do this would be as follows:

code:
<FORM ACTION="videoadd.php" enctype="multipart/form-data" method="POST">
Title: <INPUT TYPE="text" name="Title"><BR>
Rating (/10): <INPUT TYPE="text" name="Rating"><BR>
Choose a video file to upload: <input type="file" name="videofile"><BR>
Choose an image file to upload: <input type="file" name="imagefile"><BR>
<INPUT TYPE="hidden" name="UploadedBy" Value="<?PHP echo $Nickname; ?>">
<INPUT TYPE="hidden" name="Number" Value="<?PHP echo ($HighNumber+1); ?>">
<INPUT TYPE="hidden" name="Date" Value="<?PHP echo $today = date("F j, Y"); ?>">
<INPUT TYPE="hidden" name="AddFile" Value="True">
<TEXTAREA name="Description" COLS=40 ROWS=8>Write Description Here</TEXTAREA><BR><BR>
<INPUT type="submit" value="Add" style="width:100;height:40;">
</FORM>




php:
code:

<?PHP
if($_FILES["videofile"]["error"] == UPLOAD_ERR_OK) {
  $tmp_name = $_FILES["videofile"]["tmp_name"];
  $name = $_FILES["videofile"]["name"];
  move_uploaded_file($tmp_name, "Upload/$name");
}

if($_FILES["imagefile"]["error"] == UPLOAD_ERR_OK) {
  $tmp_name = $_FILES["imagefile"]["tmp_name"];
  $name = $_FILES["imagefile"]["name"];
  move_uploaded_file($tmp_name, "Upload/$name");
}

?>


however if you are going to be uploading many many files, then I would do it the other way. (but I'm not sure why its not working)
This way should work, let me know if it doesn't.
octopi




PostPosted: Sun Nov 12, 2006 2:59 pm   Post subject: (No subject)

Also I was reviewing your html code, and you look like your doing some dangerous things....It looks like your passing the next highest SQL record in the html code. This creates a race condition.

User A loads the html page, and User B loads the html page at roughly the same time. (Both would have the same number.) Then User A finally fills out the form and submits it. User A has now taken that number, so what happens when User B submits the form, with the same number?


Also you passing the date via hidden variables too. Do you trust your users? it is very easy to fake that information. (Same applies to the number) UploadedBy could also be changed to make it appear that it comes from a different user.
Numbah51




PostPosted: Sun Nov 12, 2006 9:46 pm   Post subject: (No subject)

They are very trusted users and i don't think i have to worry about the number thing because i dunno how to explain it but it should't make a difference.
Numbah51




PostPosted: Tue Nov 14, 2006 8:02 pm   Post subject: (No subject)

That still doesn't help. The WMV file still fails to upload. And its not anything about the script i don't think because i can upload 2 images and it works. Any other suggestions (if you have any) would be great.
r.3volved




PostPosted: Tue Nov 14, 2006 8:47 pm   Post subject: (No subject)

Did you check that the wmv filesize is within your upload constraints AND within the php.ini max upload range?

Sounds like it's just too big.
You could always try an ftp upload instead.
Amailer




PostPosted: Wed Nov 15, 2006 10:21 pm   Post subject: (No subject)

If the page stops loading (without an execution timeout error) then its to big :/ You have to increase your post_max_size, upload_max_filesize and max_execution_time (I think max_input_time too, check out the Related Configurations Note: for the POST method uploads)

I tired all this though and - ugh - it just takes forever to upload, would be so much faster to just give them ftp access.
Display posts from previous:   
   Index -> Programming, PHP -> PHP Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: