Hi folks,

I'm wondering if anyone has a simple upload script, to upload mp3's into a specific directory?

I can do it with images, but for some reason, when i try upload mp3's it doesn't work, can anyone help me?

Thanks in advance.

    The same upload script for images should work fine for mp3 files too, most probably u've got timout problem while uploading large files, so try to increase "maximum execution time of each script" value in your php.ini file, it's usually set to 30 seconds.

    Abraham

      What type of server do you use?

      you run your script on a local or remote server?

        on a remote server, i pay for hosting space. its a linux server.

          i don't think it's possible in your case,
          anyway ask your hosting company if they can do such a favor for you :rolleyes:

          Abraham

            hey abraham... i don't think its a timeout issue, I just tried uploading a file that was very smile, and still it didn't work, it tells me that it works, but it doesn't upload anything.

              Let me check the error message, can you send it?

                the problem is there is no error message... i'll send you my code though, k?

                
                <FORM ENCTYPE="multipart/form-data" ACTION="" METHOD="POST">
                        <p>New Music Title:<br>
                          <input type="text" name="title" class="formtex" id="title">
                        </p>
                        <p><span class="formtex">Upload New Music:<br>
                          </span> 
                          <input name="userfile1" type="file" class="formtex" id="userfile1">
                        </p>
                      <p><hr size=1>
                        <input name="submit" type="submit" class="formtex" value="Upload">
                        <br>
                        <?php
                
                $path = "../images/music/";
                $path2 = "images/music/";
                $max_size = 20000000;
                
                /*if (is_uploaded_file($userfile1)) {
                
                if ($userfile1_size>$max_size) { echo "The file is too big<br>\n"; exit; }
                
                if (($userfile1_type=="mp3") || ($userfile1_type=="mp3")) {
                
                if (file_exists($path . $userfile1_name)) { echo "The file already exists<br>\n"; exit; }
                
                $res = copy($userfile1, $path . $userfile1_name);
                if (!$res) {
                echo "upload failed!<br>\n"; exit; }
                else
                echo "1. $userfile1_name upload sucessful<br>\n";
                } else { echo "Wrong file type<br>\n"; exit; }
                
                }*/
                
                
                
                ?>
                        <?PHP
                if ($REQUEST_METHOD=="POST") {
                
                	require('config.inc');
                	$cid = mysql_connect($host,$usr,$passwd);
                
                
                			// setup SQL statement
                			$date=date( "l, M d" );
                			$date2=date( "h:i a");
                
                			$title = addslashes($title);
                			$SQL = " INSERT INTO x_music ";
                			$SQL = $SQL . "(date, date2, dir, title, imagename) VALUES ";
                			$SQL = $SQL . " ('$date', '$date2', '$path2', '$title', '$userfile1_name')";
                
                
                			#execute SQL statement
                			$result = mysql_db_query($db,"$SQL",$cid);
                			// check for error
                			if (!$result) {
                			echo("ERROR: " . mysql_error() . "\n$SQL\n");
                			}else{
                			}
                			mysql_close($cid);
                
                			print ("<font color='#990000'><b>New Music File Added!</b></font>");
                			}else{}
                ?>
                      </FORM>
                
                

                The part that is commented out, was the script I used for uploading images... and it would just tell me, wrong file type... so i commented it out...

                  I checked your script, well, weird case indeed 😕 seems PHP doesn't recognize MP3 files, it just fails to get the type and thus the size of the file, now i don't have idea now you going to get the size but can help to determine file type, use this:

                  <?
                          $array = explode (".",$userfile1_name);
                          $i = count($array);
                          $extension = strtolower($array[$i-1]);
                  ?>
                  

                  Abraham

                    thanks abraham... where would i put that into my script?

                      here's the clear code:

                      if (is_uploaded_file($userfile1)) { 
                      
                      $array = explode (".",$userfile1_name);
                      $i = count($array);
                      $extension = strtolower($array[$i-1]); 
                      
                      //	if ($userfile1_size>$max_size){
                      //		echo "The file is too big<br>\n";
                      //		exit;
                      //	} 
                      
                      if ($extension=="mp3"){ 
                      
                      	if (file_exists($path . $userfile1_name)){
                      		echo "The file already exists<br>\n";
                      		exit;
                      	}
                      
                      	$res = copy($userfile1, $path . $userfile1_name); 
                      	if (!$res)){ 
                      		echo "upload failed!<br>\n";
                      		exit;
                      	} else {
                      		echo "1. $userfile1_name upload sucessful<br>\n";
                      	}
                      
                      } else {
                      	echo "Wrong file type<br>\n";
                      	exit;
                      } 
                      
                      } 
                      

                      Good Luck!

                        WOW MAN! Thank you for all your help, your edit worked perfectly... I really apreciate it... if you wanna check out my site, go here www.dillenger.net

                        Thanks again.

                          I just thought I'd point out that the "type" of a file refers to its MIME type (in this case, it's expected to be "audio/mpeg"), not its file extension.

                            Write a Reply...