image upload
Posted: Sat Jul 30, 2011 5:33 pm
Hi,
I am uploading an image into a folder using php, here is the code:
add.php:
Ok the problem I am having is: Some images is uploading normal and some are not?
Any help will be great.
I am uploading an image into a folder using php, here is the code:
Code: Select all
<form action="add.php" method="POST" enctype='multipart/form-data'>
<input type="file" name="file" id="file" />
<input type="submit" id="Main_Search_Button">
</form>Code: Select all
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/PNG")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_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 />";
$newname = "$pid.jpeg";
if (file_exists("exchanges_images/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"exchanges_images/" . $newname);
echo "Stored in: " . "exchanges_images/" . $newname;
}
}
}
else
{
echo "Invalid file";
}
Any help will be great.