Page 1 of 1

uploading problem

Posted: Wed Dec 06, 2006 2:39 am
by corillo181
i got a code to upload picture i triad it to upload music but is not wokring is there a special way or music than picture?

Code: Select all

<form action="../phpscripts/muls.php" method="post" enctype="multipart/form-data" name="ulmusic" id="ulmusic">
  <table border="0">
    
    <tr>
      <td>song_name</td>
      <td><label>
        <input name="song" type="text" id="song" />
      </label></td>
    </tr>
    <tr>
      <td><label>song:</label></td>
      <td><input name="sfile" type="file" id="ulfile" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="Submit" value="UpLoad" /></td>
    </tr>
  </table>
</form>

Code: Select all

include_once'../includes/db.php';
//get variable
$song=$_POST['song'];
$dir='../music/hmp/';
$filesize = $_FILES['sfile']['size'];
$filetype = $_FILES['sfile']['type'];
$filename = $_FILES['sfile']['name'];
$tmpname = $_FILES['sfile']['tmp_name'];
$pos = strrpos($filename, '.');
$newname = $song . substr($filename, $pos);
$filepath = $dir . $newname;

$result=copy($tmpname, $filepath);
if(!$result){ echo " a problem occur";
}

Posted: Wed Dec 06, 2006 2:57 am
by volka
No, there's not. Maybe you've reached a data size limit.
What does print_r($_FILES); print?

Posted: Wed Dec 06, 2006 3:01 am
by corillo181
it prints this


Array ( [sfile] => Array ( [name] => Miguelito.mp3 [type] => audio/mpeg [tmp_name] => /tmp/phpB9l3Wq [error] => 0 [size] => 1877099 ) )

Re: uploading problem

Posted: Wed Dec 06, 2006 4:38 am
by Zu
corillo181 wrote:i got a code to upload picture i triad it to upload music but is not wokring
I think the most important question here is, is there an error message, and if so what is it?

Posted: Wed Dec 06, 2006 4:50 am
by CoderGoblin
You should be using move_uploaded_file rather than copy.
You may also want to check through Handling File Uploads.

Finally you may want to set the pathname/dir to the true system path name rather than a relative path name.

Posted: Wed Dec 06, 2006 7:22 am
by jito
chech max_upload_size in your php.ini. by default it's 2M.
Also take care of the execution time, use set_time_limit() for that.

Posted: Wed Dec 06, 2006 7:32 am
by volka
corillo181 wrote:it prints this


Array ( [sfile] => Array ( [name] => Miguelito.mp3 [type] => audio/mpeg [tmp_name] => /tmp/phpB9l3Wq [error] => 0 [size] => 1877099 ) )
I don't see any problem with the actual upload. Data has been received and according to error=>0 written without errors to the file shown in tmp_name

Posted: Wed Dec 06, 2006 11:03 pm
by corillo181
it was the directory that had a problem..

now what i want to know is how do i check if the upload file is a mp3?

i know to check for a picture is like this

$_FILES['ulfile']['type'] != "image/pjpeg"

but no idea for a song.

Posted: Wed Dec 06, 2006 11:06 pm
by John Cartwright
corillo181 wrote:it was the directory that had a problem..

now what i want to know is how do i check if the upload file is a mp3?

i know to check for a picture is like this

$_FILES['ulfile']['type'] != "image/pjpeg"

but no idea for a song.
searching helps Image http://www.w3schools.com/media/media_mimeref.asp