Results 1 to 3 of 3

Thread: How to save picture from url if it has no extension?

  1. #1
    Join Date
    May 2011

    Exclamation How to save picture from url if it has no extension?

    How to save picture from url if it has no extension by using php of course.
    I use curl for save images (I need a extension of that files), but there is some sort of image that I can't save, the problem in it's url's: like that: http://url.com/image.jpg?blablabla and etc. What I must do with that images if I want to download it?
    Thank you.

  2. #2
    Join Date
    Jul 2010
    The server SHOULD respond to your request with a mime-type/content-type header.

    PHP Code:

    $info curl_getinfo($ch);
    curl_close($ch); // always close handle 

    Extensions are not really important, from what I understand they only serve two purposes:
    1) to help end-users identify types of files without having to open them
    2) for operating systems to add some type of image/logo and default program associated with an extension.

    They carry absolutely zero weight as far as the file's actual contents go. The only reason your .php files are executed using PHP is because there is an apache directive more or less like this:

    <FilesMatch "\.php$">
      AddHandler x-httpd-php5.3 .php
    You can rename all of your php files jpg and add this directive:

    <FilesMatch "\.jpg$">
      AddHandler x-httpd-php5.3 .jpg

    I use (, ; : -) as I please- instead of learning the English language specification: I decided to learn Scheme and Java;

  3. #3
    Join Date
    Aug 2004
    You could also try loading it into getimagesize(), and see what it finds. It returns an array, with element "2" being a PHP constant for the image type, and element 'mime' being the MIME type (or the function returns Boolean false if it does not recognize it as a known image type).
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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