Hi, Im part way through creating a php script to upload mp3 files into a directory ($uploadDir). It wasn’t working so I stuck in a print_r() function to have a look at the $_FILES[‘mp3’] array and I saw that the output was:
Array
(
[name] => The Wurzles - Combine Harvester.mp3
[type] =>
[tmp_name] =>
[error] => 1
[size] => 0
)
If you want any more info on the logic of the script or anything like that just ask, any help which will enable me to see the problem would be great.
if(isset($_GET['addsong']))
{
$aid = $_GET['addsong'];
$name = $_POST['name'];
$track = $_POST['track'];
$length = ''.$_POST['lm'].':'.$_POST['ls'].'';
if($length==':')
{
$length='';
}
if(!isset($_FILES['mp3']))
{
$location = ':asd:noMp3:asd:';
}
else
{
echo '<pre>';
print_r($_FILES['mp3']);
echo '</pre>';
$mimes = array('audio/x-mp3', 'audio/x-mpeg-3', 'audio/mpeg3');
if(is_uploaded_file($_FILES['mp3']['tmp_name']) && inarray($_FILES['mp3']['type'], $mimes))
{
$uploadDir = '../music/';
$uploadFile = $uploadDir . urlencode($name.$aid);
if (move_uploaded_file($_FILES['mp3']['tmp_name'], $uploadFile))
{
$location = $uploadFile;
echo 'Uploaded MP3!';
}
else
{
$location = ':asd:noMp3:asd:';
echo 'Error: Could Not Upload MP3!\
';
echo 'Upload Directory: '.$uploadFile.'\
';
echo 'TMP Name: '.$_FILES['mp3']['tmp_name'].'\
';
echo 'TMP Name: '.$_FILES['mp3']['name'].'\
';
echo 'MIME: '.$_FILES['mp3']['type'].'\
';
}
}
else
{
$location = ':asd:noMp3:asd:';
echo 'Error: Could Not Upload MP3!\
';
echo 'Upload Directory: '.$uploadFile.'\
';
echo 'TMP Name: '.$_FILES['mp3']['tmp_name'].'\
';
echo 'TMP Name: '.$_FILES['mp3']['name'].'\
';
echo 'MIME: '.$_FILES['mp3']['type'].'\
';
}
}
$sql1 = "INSERT INTO ra_songs (id, name, track, length, location) VALUES ('', '$name', '$track', '$length','$location')";
$sql1 = mysql_query($sql1);
$sid = mysql_insert_id();
$sql2 = "INSERT INTO ra_songs_alb_ref (aid, sid) VALUES ('$aid','$sid')";
$sql2 = mysql_query($sql2);
if ($sql1 && $sql2)
{
echo "<h2>Song: <strong><em>$name</em></strong> submitted successfully!</h2>";
include('includes/footer.inc.php'); //include the footer
exit();
}
else
{
echo "<h2>Song: <strong><em>$name</em></strong> not submitted!</h2>";
include('includes/footer.inc.php'); //include the footer
mysql_error();
exit();
}
}
<h2>Add A Song</h2>
<form action="discogactions.php?addsong=<?=$aid?>" method="post" enctype="multipart/form-data" >
<table>
<tr>
<th><label for="name">Name:</label></th>
<td colspan="3"><input type="text" name="name" id="name" /></td>
</tr>
<tr>
<th><label for="track">Track:</label></th>
<td colspan="3"><input type="text" name="track" id="track" /></td>
</tr>
<tr>
<th><label for="lm">Length:</label></th>
<td colspan="3"><input type="text" name="lm" id="lm" size="2" />:<input type="text" name="ls" id="ls" size="2" /></td>
</tr>
<tr>
<th rowspan="3"><label for="mp3">Mp3:</label></th>
<td colspan="3"><input type="file" id="mp3" name="mp3" /></td>
</tr>
<tr>
<td colspan="3">(must be .mp3)</td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="regSubmit" value="Submit"></td>
<td><input type="reset" name="Reset" value="Reset" /></td>
</tr>
</table>
</form>