Reputation: 127
i want to upload video,audio, images, pdf, ppt, word files and then save them into a directory...here is my code for uploading,.,,, there is no error but no output as well... when i open the folder thres no image file in it... plus it would be very helpful if u guys tell me how should i upload pdf,word and video files as well...
Heres what I have so far:
this is add-material.php
<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" />
as my form is pretty big so im pasting pnly the relevant lines of code here
this is add-material-action.php
$allowedExts = array("jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES["uploadedfile"]["name"]));
if (( ($_FILES["uploadedfile"]["type"] == "image/gif")
|| ($_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("learningmaterial/" . $_FILES["uploadedfile"]["name"]))
{
echo $_FILES["uploadedfile"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["uploadedfile"]["tmp_name"],
"learningmaterial/" . $_FILES["uploadedfile"]["name"]);
echo "Stored in: " . "learningmaterial/" . $_FILES["uploadedfile"]["name"];
}
}
else
{
echo "Invalid file";
}
thanx in advance :)
Upvotes: 0
Views: 617
Reputation: 2187
I had the same problem using WinSCP. All I had to do is refresh the server-side so that I could see the new uploads.
Upvotes: 0
Reputation: 9
try this you need a return true for success
if(!move_uploaded_file(move_uploaded_file($_FILES["uploadedfile"]["tmp_name"],
"learningmaterial/" . $_FILES["uploadedfile"]["name"]))
{
echo "can't move file";
}
Upvotes: 0
Reputation: 2790
It seems you should at the very least get a "Invalid File error." So it's interesting that you're not getting any output after processing.
I would recommend the following:
Similar to $allowedExts = array("jpg", "jpeg", "gif", "png"), I would do the same for the mime-types and do an in_array(type, collection)
This makes it easy to add additional extensions and mime-types to the whitelist.
I would also print specific error messages to be more useful
if (!in_array($mime, $mimeCollection)) {
echo "Invalid mime-type";
} else if (!in_array($ext, $extCollection)) {
echo "Invalid file extension";
} else if ($size > $max) {
echo "File is too large";
}
... additional checks
I would also enable error reporting to see if something else is going on since you're not getting any output.
error_reporting(E_ALL ^ E_NOTICE);
I prefer to check my logs, however, vs enabling reporting in my scripts.
Upvotes: 1
Reputation: 109
You have taken
$allowedExts = array("jpg", "jpeg", "gif", "png");
But you want to upload video,audio, images, pdf, ppt, word. So first of all edit your extension list as follows
$allowedExts = array("jpg", "jpeg", "gif", "png","txt","doc","pdf","mp3");
add all extensions you want to upload code seems to be perfectly fine, please check if you have permissions in required folder for uploading
Upvotes: 1