Hi everyone :)
i am doing my final year project in PHP and MYSQL and i am just at beginner level of php.i found this forum really helpful. in my teacher module i allowed the teacher to upload video, audio, mp3 and image files and here is my code... i trying from last two days but the code is not showing any error neither its uploading the file..please check my code and mend a soultion.. i'd be thankfull :)
add-material.php
i've added only the relevant lines bcoz the form is pretty big
<form id="form" method="post" action="add-material-action.php" enctype="multipart/form-data">
<label for="file">Upload Your File Here:</label><input type="file" name="uploadedfile" id="uploadedfile"/><br /><br />
<input class="mybutton" type="submit" name="Add Material" class="button" value="Add Material" />
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"))
&& ($_FILES["uploadedfile"]["size"] < 20000)
&& 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!";
}
?>