Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I got this php code online to load m3p files to my server, and it works good except I would like to be able to upload multiple songs at once by adding more file upload boxes. I have tried on my own but I cannot seem to get it right, when I add other boxes I still only get one track. I have just started to learn php on my own so I am still new to it all. Thank you for any help.


here is the form html:

HTML
<form action="/loadmp3.php" method="post" enctype="multipart/form-data">

<input type="file" name="file" size="40" />

<br /><br />

<input type="submit" name="submit" value="Upload" />

<br /><br />

<span style="font-family: verdana; font-size: 12px;">* only mp3 files under 2 megabytes are allowed.</span>

</form>






and this is the php:

PHP
<?php

if($_POST['submit']=="Upload") {
    if ($_FILES['file']['name'] != "") {
            if (($_FILES['file']['type'] == "audio/mpeg") || ($_FILES['file']['type'] == "application/force-download")) {
                if ($_FILES["file"]["size"] < 16777216) {           
                        move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]);
                       echo "File has been stored in your uploads directory.";}
else {    echo "Please upload a file that is under 2 mb!";}
} else {
    echo "Please upload a mp3 file!";
    exit;}
} else {     echo "Please enter a file.";}
}
?>
Posted
Updated 16-Jan-12 20:25pm
v2

1 solution

The type of file to upload (MPEG3 or not) does not matter at all. I don't see where is your HTML which would allow the user to specify big number of files. The usual simple technique is to allow the user to post how many input controls to present, process this post on server side (with PHP in your case) and generate a form dynamically with required number of input controls with the type="file". The implementation of this is just trivial.

Yes, this is the usual technique, but it is not convenient for the user who needs to browse for each file separately and can easily make mistakes. Why it's limited to file input controls? I don't know. To me, it looks like a big void in the standards.

There is much nicer solution where the user is given a dialog box with multi-select feature and can specify many files at once; please see: http://forums.asp.net/t/1555692.aspx/1[^].

There is only one caveat with this, but to me, it's fatal: this solution is based on Microsoft ActiveX and hence not portable. However, you can consider it for some practical purposes.

Any other ideas? Well, you can request the user to send just one file, but that file could compress a number of files in one. It's easy enough to process the compressed file on the server side to extract individual files. How about that? Well, for me as a user it would be a pretty good method, but I doubt that many other users would be able to accept it at all. I'm pretty much sure, most users won't use this method.

—SA
 
Share this answer
 
Comments
rockoclark 17-Jan-12 2:22am    
Still new at this, so you kinda lost me there, but thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900