mp3 file upload
Posted: Mon May 08, 2006 1:42 am
Hi
My code is successfully uploading a file, but it appears to be just the file name when I need all the info in the mp3. It's not saving the music. I have read the documentation on uploads in the php manual but it doesnt cover what I need. What am I missing to get the mp3 to upload properly? Here's my code:
Thanks for taking a look...
My code is successfully uploading a file, but it appears to be just the file name when I need all the info in the mp3. It's not saving the music. I have read the documentation on uploads in the php manual but it doesnt cover what I need. What am I missing to get the mp3 to upload properly? Here's my code:
Code: Select all
<html>
<head>
<title>Administration - upload new files</title>
</head>
<body>
<h1>Upload new news files</h1>
<form enctype="multipart/form-data" action="upload.php" method=post>
<input type="hidden" name="MAX_FILE_SIZE" value="40000000">
Upload this file: <input name="userfile" type="file">
<input type="submit" value="Send File">
</form>
</body>
</html>
<html>
<head>
<title>Uploading...</title>
</head>
<body>
<h1>Uploading file...</h1>
<?php
if ($_FILES['userfile']['error'] > 0)
{
echo 'Problem: ';
switch ($_FILES['userfile']['error'])
{
case 1: echo 'File exceeded upload_max_filesize erg'; break;
case 2: echo 'File exceeded max_file_size'; break;
case 3: echo 'File only partially uploaded'; break;
case 4: echo 'No file uploaded'; break;
}
exit;
}
// Does the file have the right MIME type?
if ($_FILES['userfile']['type'] != 'audio/mpeg')
{
echo 'Problem: file is not right type';
exit;
}
// put the file where we'd like it
$upfile = 'uploads/'.$_FILES['userfile']['name'];
if (is_uploaded_file($_FILES['userfile']['tmp_name']))
{
if (!move_uploaded_file($_FILES['userfile']['tmp_name'], $upfile))
{
echo 'Problem: Could not move file to destination directory';
exit;
}
}
else
{
echo 'Problem: Possible file upload attack. Filename: ';
echo $_FILES['userfile']['name'];
exit;
}
echo 'File uploaded successfully<br><br>';
// reformat the file contents
$fp = fopen($upfile, 'r');
$contents = fread ($fp, filesize ($upfile));
fclose ($fp);
$contents = strip_tags($contents);
$fp = fopen($upfile, 'w');
fwrite($fp, $contents);
fclose($fp);
// show what was uploaded
// echo 'Preview of uploaded file contents:<br><hr>';
// echo $contents;
// echo '<br><hr>';
?>
</body>
</html>Thanks for taking a look...