Page 1 of 1

image upload

Posted: Sat Jul 30, 2011 5:33 pm
by YoussefSiblini
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.

Re: image upload

Posted: Sun Jul 31, 2011 9:31 am
by social_experiment
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" />

Re: image upload

Posted: Sun Jul 31, 2011 9:48 am
by YoussefSiblini
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

Re: image upload

Posted: Sun Jul 31, 2011 10:18 am
by YoussefSiblini
Thank youuuuuuuuuuuuuuuu, I reduced the size of the image and it charmed, this is the best forum ever. :)))))))))))