Results 1 to 3 of 3

Thread: validating images in php

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    From the UK
    Posts
    422

    Thumbs up validating images in php

    hi

    i have a simple form where the user can enter in a url of an image, and then this image is displayed on a page. as of yet, there is no validation to check the url supplied. obviously i need to fix this. i have a few questions and id like to hear your points:

    firstly, i can do a check to see if the url entered ends in jpg/jpeg/gif/png/bmp but is there a more widespread check available? also i would like to check to see if the image even exists, ie. whether its not been removed etc. is there a way to accomplish all this?

    secondly, i am allowing users to enter images from anywhere on the net. the images act as links direct to the website they are taken from. in this case i dont think im stealing copyright, however maybe i need to consider bandwidth problems? if i had 100 images from one site, and each time a user comes to my site this loads 100 of those images, then it could be a considerable load. is there a better way around this? i thought of uploading files, but it seems to be a lot of work for such a small part of my site.

    thanks for your thoughts and advice,

  2. #2
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: validating images in php

    Here is a function which will check if a file exists on a remote server:

    http://www.php.net/manual/en/functio...open.php#39948

    It creates a HTTP request for the file, if the server returns 200 OK then it exists, or if it returns 404 Error then it does not exist.

    You can add your own code to make it check the extension for .bmp jpg etc.

    The only problem you have with using images on other servers is they could be removed/renamed/moved at any time after you have checked it with your function.
    Chris

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    From the UK
    Posts
    422

    Re: validating images in php

    thanks for the link, ill check it out for sure

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width