Get ready for BLACK FRIDAY shopping starting in

Forums

PHP

This topic is locked

Audio/mp3 file upload in php form

Posted 06 Jun 2008 07:12:19
1
has voted
06 Jun 2008 07:12:19 Parry Jaan posted:
I am using a form to upload mp3 files. This form works great for uploading images (jpg gif etc.) but when try to upload mp3 files, I get an error. Please help.

This is the html code
----------- Code starts here -----------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Best Craigs Girl</title>
<style type="text/css">
<!--
body {
background-color: #CC66CC;
}
.style1 {
color: #000000;
font-weight: bold;
}
-->
</style></head>

<body>
<form action="Upload.php" method="post" enctype="multipart/form-data">
<div align="center">
<p><strong><u><font color="#ffffff" size="5">Welcome to Best Craigs Girl</font></u></strong></p>
<p> </p>
<table width="426" height="31" border="1">
<tr>
<td bordercolor="#000000" bgcolor="#66FF00"><div align="center">
<h2><span class="style1"> Upload your Profile </span></h2>
</div></td>
</tr>
</table>
<p> </p>
<table width="432" border="0">
<tr>
<td width="125"><div align="left">Name:
<label></label>
</div></td>
<td width="399"><div align="left">
<input name="Name" type="text" id="Name">
</div></td>
</tr>
<tr>
<td><div align="left">E-mail:</div></td>
<td><div align="left">
<input name="Email" type="text" id="Email">
</div></td>
</tr>
<tr>
<td><div align="left">City/Location : </div></td>
<td><div align="left">
<input name="Location" type="text" id="Location">
</div></td>
</tr>
<tr>
<td><div align="left">Contact No. </div></td>
<td><div align="left">
<input name="Phone" type="text" id="Phone">
</div></td>
</tr>
<tr>
<td><div align="left">Type:</div></td>
<td><div align="left">
<input name="Type" type="text" id="Type">
</div></td>
</tr>
<tr>
<td><div align="left">1/2 Hour : </div></td>
<td><div align="left">
<input name="HalfHour" type="text" id="HalfHour">
</div></td>
</tr>
<tr>
<td><div align="left">1 Hour : </div></td>
<td>
<div align="left">
<input name="OneHour" type="text" id="OneHour">
</div></td>
</tr>
<tr>
<td><div align="left">Image : </div></td>
<td>
<div align="left">
<input type="file" name="file" id="file" />
</div></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="submit" value="Submit" />
</div></td>
</tr>
</table>
</div>
</form>

</body>
</html>

------------ Html code ends here -----------

--------This is the Php Upload.php code -----------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="application/octet-stream">
<title>Best Craigs Girl</title>
<style type="text/css">
<!--
body {
background-color: #CC66CC;
}
-->
</style></head>

<body>
<?php
if ((($_FILES["file"]["type"] == "audio/mp3"
|| ($_FILES["file"]["type"] == "audio/mp4"
|| ($_FILES["file"]["type"] == "audio/avi")
/*&& ($_FILES["file"]["size"] < 20000)*/)
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
/* echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
*/
/* Setting date to send mail */
$fname = $_POST['Name'];
$email = $_POST['Email'];
$phone = $_POST['Phone'];
$type = $_POST['Type'];
$halfhour = $_POST['HalfHour'];
$onehour = $_POST['OneHour'];
$f_name = $_FILES["file"]["name"];
$message = "<table width='600' border='0' cellspacing='2' cellpadding='3'>

<tr valign='top'>
<td><div align='right'><strong><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>First Name:</font></strong></div></td>
<td><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>$fname</font></td>
</tr>
<tr valign='top'>
<td><div align='right'><strong><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>E-mail:</font></strong></div></td>
<td><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>$email</font></td>
</tr>
<tr valign='top'>
<td><div align='right'><strong><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>Contact No.:</font></strong></div></td>
<td><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>$phone</font></td>
</tr>
<tr valign='top'>
<td><div align='right'><strong><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>Type:</font></strong></div></td>
<td><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>$type</font></td>
</tr>
<tr valign='top'>
<td><div align='right'><strong><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>Half Hour:</font></strong></div></td>
<td><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>$halfhour</font></td>
</tr>
<tr valign='top'>
<td><div align='right'><strong><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>One Hour:</font></strong></div></td>
<td><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>$onehour</font></td>
</tr>
<tr valign='top'>
<td><div align='right'><strong><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>File Name :</font></strong></div></td>
<td><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>$f_name</font></td>
</tr>
</table>";

$to=" ";
$subject = "New Profile uploaded on Best Craigs Girl";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ".$email."\r\n";

mail($to,$subject, $message,$headers);
/* */

if (file_exists("upload/" . $_FILES["file"]["name"]))
{
// echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
// echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
</body>
</html>
<html>
<table border="1" width="88%">
<tr>
<td width="100%">
<p align="center"><u><font color="#FFFFFF" size="5"><b>Welcome to Best Craigs
Girl</b></font></u></td>
</tr>
<tr>
<td width="100%"><font color="#000000">     This website is intended for people visiting craigs list
searching for girls. On Craigs list many girls post their ads many time
and each day there are 1000's of listing. For a visitor it becomes very
difficult to find the right girl he is looking for. Also many of them are
fake providing link to some website. <br>
</font>
     In this website (in fact there is only one page on this
website) you can find girls. Girls are listed by location/area 
and there are other details too. You can click on table heading to sort
the table based on your needs (default it is sorted based on location). I am looking forward for your
suggestions/improvements.<br>
     To put your listing for Free send email to
<a href="mailto: "><b><font color="#FFFF00"> </font></b><br>
</a>     <font color="#FFFFFF">Please inform us if any of  following
information is not correct. When visiting girls please tell her you found her
at "BestCraigsGirl.com"</font> </td>
</tr>
</table>
<br>
<br>
<br>
<br>
<br>
<br>
<center>
<font size="4"> Thank you for uploading your profile.<br>
Your profile will be reviewd and it will be on site in 24 hrs. </font>
</center>
</html>
-------------- Php code ends here ----------

Whenever I try to upload mp3 file I get error "Invalid file". So when it tries to execute first if loop of php file , it fails and goes to else part. Please help

Thanks
Parry

Reply to this topic