PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
YoussefSiblini
Forum Contributor
Posts: 206 Joined: Thu Jul 21, 2011 1:51 pm
Post
by YoussefSiblini » Sat Jul 30, 2011 5:33 pm
Hi,
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>
add.php:
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";
}
Ok the problem I am having is: Some images is uploading normal and some are not?
Any help will be great.
Last edited by
Benjamin on Sat Jul 30, 2011 9:28 pm, edited 1 time in total.
Reason: Added [syntax=php|sql|css|javascript] and/or [text] tags.
social_experiment
DevNet Master
Posts: 2793 Joined: Sun Feb 15, 2009 11:08 am
Location: .za
Post
by social_experiment » Sun Jul 31, 2011 9:31 am
Since some of the files are uploading and others not, it could be a size problem. You should add a hidden field within the html form
Code: Select all
<!-- where 'value' is the maximum size of the value to be uploaded -->
<input type="hidden" name="MAX_FILE_SIZE" value="102400" />
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
YoussefSiblini
Forum Contributor
Posts: 206 Joined: Thu Jul 21, 2011 1:51 pm
Post
by YoussefSiblini » Sun Jul 31, 2011 9:48 am
Sorry I am not that good in php, I am new into it.
What I meant to do after I put the hidden field how to process it in the add.php
YoussefSiblini
Forum Contributor
Posts: 206 Joined: Thu Jul 21, 2011 1:51 pm
Post
by YoussefSiblini » Sun Jul 31, 2011 10:18 am
Thank youuuuuuuuuuuuuuuu, I reduced the size of the image and it charmed, this is the best forum ever.
))))))))))