PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
corillo181
Forum Commoner
Posts: 76 Joined: Wed Apr 26, 2006 3:02 pm
Post
by corillo181 » Wed Dec 06, 2006 2:39 am
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> </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";
}
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Wed Dec 06, 2006 2:57 am
No, there's not. Maybe you've reached a data size limit.
What does print_r($_FILES); print?
corillo181
Forum Commoner
Posts: 76 Joined: Wed Apr 26, 2006 3:02 pm
Post
by corillo181 » Wed Dec 06, 2006 3:01 am
it prints this
Array ( [sfile] => Array ( [name] => Miguelito.mp3 [type] => audio/mpeg [tmp_name] => /tmp/phpB9l3Wq [error] => 0 [size] => 1877099 ) )
Zu
Forum Commoner
Posts: 33 Joined: Wed Dec 06, 2006 4:21 am
Post
by Zu » Wed Dec 06, 2006 4:38 am
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?
CoderGoblin
DevNet Resident
Posts: 1425 Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany
Post
by CoderGoblin » Wed Dec 06, 2006 4:50 am
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.
jito
Forum Commoner
Posts: 85 Joined: Sat Mar 25, 2006 4:32 am
Location: india
Post
by jito » Wed Dec 06, 2006 7:22 am
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.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Wed Dec 06, 2006 7:32 am
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
corillo181
Forum Commoner
Posts: 76 Joined: Wed Apr 26, 2006 3:02 pm
Post
by corillo181 » Wed Dec 06, 2006 11:03 pm
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.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Wed Dec 06, 2006 11:06 pm
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
http://www.w3schools.com/media/media_mimeref.asp