Jump to content

Upload Validation


mattyvx

Recommended Posts

Hi all,

 

I've been struggling to develop a robust image upload validation script. I have an area on my site where users can upload a profile picture into a directory so, to keep it clean and safe here is what I want:

 

1) Script must work in IE and Firefox

2) Script must only allow image files to be uploaded

3) Images shouldn't be unreasonable in size say 4mb max.

 

Currently i'm using this

 

if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 40000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    if (file_exists("profiles/images/$filegif"))
      {
unlink("profiles/images/$filegif");
      }  
    if (file_exists("profiles/images/$filejpeg"))
      {
unlink("profiles/images/$filejpeg");
      }
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "profiles/images/" .$name);
     }

//.... send me email to let me view picture ....//

  }
  else
  {
  echo "Invalid file - Only Gif or Jpeg files may be uploaded.";
  
///... send me error message to let me know user having problems .../// 

  }
}

 

Some users upload fine (is this browser compatability?), mostly I get alot or error messages though and have to upload manually.

 

Thanks in advance!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.