dharvell
12-13-2008, 12:50 AM
As the title states, I need to upload MP3 files via PHP. For whatever reason, it just doesn't seem to work. Following is my script:
<?
$need_auth = true;
include("inc/connect.php");
include("inc/session.php");
if(($_FILES["file"]["type"] == "audio/mpeg") && ($_FILES["file"]["size"] < 10485760))
{
if($_FILES["file"]["error"] > 0)
{
echo "Error: " .$_FILES["file"]["error"]. "<br />";
}
else
{
if(file_exists("media/" .$_SESSION["username"]. "/" .$_FILES["file"]["name"]))
{
echo "File already exists.";
}
else
{
$addFile = $_FILES["file"]["name"];
move_uploaded_file($_FILES["file"]["tmp_name"],"media/" .$_SESSION["username"]. "/" .$addFile);
echo "Upload successful. Click <a href=\"controlPanel.php?userId=" .$_SESSION["username"]. "\">
<META HTTP-EQUIV=\"refresh\" content=\"0; URL=controlPanel.php?userId=" .$_SESSION["username"]. "\">";
}
}
}
else
{
echo "something went wrong";
}
?>
For the record, this is the HTML form that calls the above script:
<form name="uploadMusic" action="doUploadMusic.php" method="post" enctype="multipart/form-data">
<table width="500" height="500" border="0" cellpadding="0" cellspacing="5">
<tr>
<td width="500" height="25" align="left" valign="top" colspan="2">music upload:</td>
</tr>
<tr>
<td width="200" height="15" align="left" valign="top" class="darkText"><font color="red" size="-2">*</font> track to upload (10MB max):</td>
<td width="300" height="15" align="left" valign="top"><input type="file" name="file"></td>
</tr>
<tr>
<td width="200" height="15"></td>
<td width="300" height="15" align="left" valign="top"><input type="submit" name="submit" value="upload"></td>
</tr>
<tr>
<td width="500" align="left" valign="top" colspan="2"><font color="red" size="-2">by uploading music, you agree that you have read and agree to the <span class="redText" onMouseOver="style=cursor: hand; text-decoration: underline;" onClick="window.open('musicSubmissionAgreement.php','music terms',config='height=480,width=640,toolbar=no,menubar=0,status=0,scrollbars=1');">Music Submission Terms and Agreement</span>.</font></td>
</tr>
</table>
</form>
For kicks and grins, I did a print_r of what was happening. The output was:
Array
(
[name] => Pigs To The Slaughter.mp3
[type] =>
[tmp_name] =>
[error] => 1
[size] => 0
)
The thing that confuses me is that the image upload script that I modeled this after works just fine. Any ideas?
Thanks.
+dharvell
<?
$need_auth = true;
include("inc/connect.php");
include("inc/session.php");
if(($_FILES["file"]["type"] == "audio/mpeg") && ($_FILES["file"]["size"] < 10485760))
{
if($_FILES["file"]["error"] > 0)
{
echo "Error: " .$_FILES["file"]["error"]. "<br />";
}
else
{
if(file_exists("media/" .$_SESSION["username"]. "/" .$_FILES["file"]["name"]))
{
echo "File already exists.";
}
else
{
$addFile = $_FILES["file"]["name"];
move_uploaded_file($_FILES["file"]["tmp_name"],"media/" .$_SESSION["username"]. "/" .$addFile);
echo "Upload successful. Click <a href=\"controlPanel.php?userId=" .$_SESSION["username"]. "\">
<META HTTP-EQUIV=\"refresh\" content=\"0; URL=controlPanel.php?userId=" .$_SESSION["username"]. "\">";
}
}
}
else
{
echo "something went wrong";
}
?>
For the record, this is the HTML form that calls the above script:
<form name="uploadMusic" action="doUploadMusic.php" method="post" enctype="multipart/form-data">
<table width="500" height="500" border="0" cellpadding="0" cellspacing="5">
<tr>
<td width="500" height="25" align="left" valign="top" colspan="2">music upload:</td>
</tr>
<tr>
<td width="200" height="15" align="left" valign="top" class="darkText"><font color="red" size="-2">*</font> track to upload (10MB max):</td>
<td width="300" height="15" align="left" valign="top"><input type="file" name="file"></td>
</tr>
<tr>
<td width="200" height="15"></td>
<td width="300" height="15" align="left" valign="top"><input type="submit" name="submit" value="upload"></td>
</tr>
<tr>
<td width="500" align="left" valign="top" colspan="2"><font color="red" size="-2">by uploading music, you agree that you have read and agree to the <span class="redText" onMouseOver="style=cursor: hand; text-decoration: underline;" onClick="window.open('musicSubmissionAgreement.php','music terms',config='height=480,width=640,toolbar=no,menubar=0,status=0,scrollbars=1');">Music Submission Terms and Agreement</span>.</font></td>
</tr>
</table>
</form>
For kicks and grins, I did a print_r of what was happening. The output was:
Array
(
[name] => Pigs To The Slaughter.mp3
[type] =>
[tmp_name] =>
[error] => 1
[size] => 0
)
The thing that confuses me is that the image upload script that I modeled this after works just fine. Any ideas?
Thanks.
+dharvell