0

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!";
}

?>
3
Contributors
8
Replies
9
Views
4 Years
Discussion Span
Last Post by Riu 2009
0

this happnes, when your server has limit of some filesize, you can see in php.ini, for paramater related to file upload, you need to increase that sizes

0

i just uploaded 328 kb image file but it wasnt uploaded..isnt thre any thing wrong in the code???

0

Your code is fine
only problem with conditon on line 15 above

($_FILES["uploadedfile"]["size"] < 20000)

this says your file must be bigger then 20000 bytes, if you try file smaller then this size it will not upload.

0

@urtrivedi thanks for ur interest :)

its saying your file must be smaller then 20000 bytes < is sign of smaller than :)
yup i've allowed it to upload...

1

I made one change. just added strtolower function to extension

$extension = strtolower(end(explode(".", $_FILES["uploadedfile"]["name"])));

and with <20000, you can upload file upto size of 20 KB ONLY, bigger file then 20kb will not upload.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.