hi php geniuses :)
a simple question for u ppl here's my code and i want to upload all files i.e. images, videos, audios, ppt, pdf etc but here ican only upload the images successfully.. when i upload audio file it gives following error. please check my code and suggest a solution tahnx in advance :)
this is add-material.php
<div class="span-18 last">
<h2 class="alt">Add Material</h2>
<form id="form" method="post" action="add-material-action.php" enctype="multipart/form-data">
<label for="title">Title:</label><input type="text" name="title" id="title" class="text "value="" /><br />
<label for="url">Url:</label><input type="text" name="url" id="url" class="text" value="" /><br />
<label>Source:</label>
<input type="radio" name="source" value="E" checked />External
<input type="radio" name="source" value="I" />Internal<br /><br />
<label for="description">Course Description:</label><br /><textarea name="description" id="description"></textarea> <br />
<label for="external_id">External Id:</label><input type="text" class="text" name="external_id" value="" /><br /><br />
<label for="file">Upload Your File Here:</label><input type="file" name="uploadedfile" id="uploadedfile"/><br /><br />
<label for="internalfilename">Internal File Name:</label><input type="text" class="text" name="internalfilename" value="" /><br /><br />
<label for="internalfilesize">File Size (for internal files only):</label><input type="text" name="internalfilesize" class="text" value="" /><br /><br />
<label for="externalduration">Duration (Only for externalfiles):</label><input type="text" name="externalduration" class="text" value="" /><br /><br />
<label for="type">Type:</label>
<select name="type" value="<?php echo $type; ?>">
<optgroup label="VIDEO">
<option value="youtube video">youtube video</option>
<option value="vimeo video">vimeo video</option>
<option value="Dailymotion video">Dailymotion video</option>
</optgroup>
<optgroup label="AUDIO">
<option value="youtube audio">Youtube Audio</option>
</optgroup>
<optgroup label="Images">
<option value="Flickr">Flickr</option>
<option value="Picasa">Picasa</option>
<option value="Slide Share">Slide Share</option>
</optgroup>
<optgroup label="PDF">
<option value="Online Documents">Online Documents</option>
</optgroup>
<optgroup label="Internal Files">
<option value="image">Image</option>
<option value="audio">Audio</option>
<option value="video">Video</option>
<option value="ppt">Presentation</option>
</optgroup>
</select>
<br />
<br />
<label>Choose Course:</label>
<?php
$con=mysql_connect($dbserver,$dbusername,$dbpassword);
if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db($dbname, $con);
$result = mysql_query("SELECT * FROM courses WHERE(accountsid='".$id."')");
echo "<select name='coursesid'>\n";
while($row = mysql_fetch_array($result))
{
echo "<option value='".$row['id'] . "'";
if ($_POST["courseid"]==$row['id'])
echo " selected='selected'";
echo ">" . $row['title'] . "</option>\n";
}
echo "</select>\n";
mysql_close($con);
?>
<br />
<br />
<label>Order:</label>
<select type="text" name="order" value="<?php echo $order; ?>" >
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
<br />
<br />
<input class="mybutton" type="submit" name="Add Material" class="button" value="Add Material" />
</form>
</div>
and this is my add-material-action.php
<?php
$allowedExts = array("jpg", "jpeg", "gif", "png","txt","doc","pdf","mp3","mp4"."ppt");
$extension = end(explode(".", $_FILES["uploadedfile"]["name"]));
if (( ($_FILES["uploadedfile"]["type"] == "image/gif")
|| ($_FILES["uploadedfile"]["type"] == "audio/mpeg")
|| ($_FILES["uploadedfile"]["type"] == "video/mp4")
|| ($_FILES["uploadedfile"]["type"] == "application/msword")
|| ($_FILES["uploadedfile"]["type"] == "application/pdf")
|| ($_FILES["uploadedfile"]["type"] == "application/vnd.ms-powerpoint")
|| ($_FILES["uploadedfile"]["type"] == "text/plain")
|| ($_FILES["uploadedfile"]["type"] == "application/pdf")
|| ($_FILES["uploadedfile"]["type"] == "image/jpeg")
|| ($_FILES["uploadedfile"]["type"] == "image/png")
|| ($_FILES["uploadedfile"]["type"] == "image/pjpeg"))
&& in_array($extension, $allowedExts))
{
if ($_FILES["uploadedfile"]["error"] > 0)
{
echo "Return Code: " . $_FILES["uploadedfile"]["error"] . "<br />";
}
elseif (file_exists("graphics/learningmaterial/" . $_FILES["uploadedfile"]["name"]))
{
echo $_FILES["uploadedfile"]["name"] . " already exists. ";
}
$target_path = "graphics/learningmaterial/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
}
}
else
{
echo "There was an error uploading the file, please try again!";
}
?>
<?php
$title=$_POST['title'];
$url=$_POST['url'];
$source=$_POST['source'];
$description=$_POST['description'];
$extid=$_POST['external_id'];
$filename=$_POST['internalfilename'];
$filesize=$_POST['internalfilesize'];
$duration=$_POST['externalduration'];
$courseid=$_POST['coursesid'];
$type=$_POST['type'];
$order=$_POST['order'];
$con=mysql_connect($dbserver,$dbusername,$dbpassword);
if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db($dbname, $con);
$sql=("INSERT INTO learningmaterial VALUES (NULL,'".$title."', '".$url."','".$source."','".$description."','".$extid."','".$filename."','".$filesize."','".$target_path."','".$duration."','".$courseid."','".$type."','".$order."')");
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo header("Location:manage-material.php?status=1&id=".$courseid);
exit();
mysql_close($con);
?>