Edmonds Commerce Logo
  • home
    • blog
  • ecommerce
    • product catalogue
    • order processing
    • customer services
    • stock control
    • human resources
    • management information
  • development
    • oscommerce
    • php
    • mysql
    • open source
    • performance tuning
  • design
  • marketing
  • contact us
    • pricing

Edmonds Commerce Blog

Freelance PHP Ecommerce and SEO Developer in the UK

Latest Posts

CRELoaded Remove Google Ads -
ICECat Integration with osCommerce, Magento etc
Magento UK
PHP Cached Download Function

Most Popular Posts

PHP Email Attachment Function Freelance osCommerce UK Ultimate osCommerce Checkout - Fast and Friendly PHP : Dead Easy Excel Export

PHP Save Images Using cURL

March 18th, 2008
Read More curl, php

Some hosts disabled the ini setting allow_url_fopen. This also means that the ability to easily grab images by calling imagecreatefromjpeg($img) where $img is a url for an external image does not work.

This is a shame as this technique is pretty easy..

PLAIN TEXT
PHP:
  1. $remote_img = 'http://www.somwhere.com/images/image.jpg';
  2. $img = imagecreatefromjpeg($remote_img);
  3. $path = 'images/';
  4. imagejpeg($img, $path);

However I was tearing my hair out trying to get a product feed integration system to work on a host that has disabled the allow_url_fopen mechanism which meant the above wouldnt work.

Thankfully cURL was still working. So here is the function I made for grabbing and saving an image using cURL instead:

PLAIN TEXT
PHP:
  1. //Alternative Image Saving Using cURL seeing as allow_url_fopen is disabled - bummer
  2. function save_image($img,$fullpath){
  3.     $ch = curl_init ($img);
  4.     curl_setopt($ch, CURLOPT_HEADER, 0);
  5.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  6.     curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
  7.     $rawdata=curl_exec($ch);
  8.     curl_close ($ch);
  9.     if(file_exists($fullpath)){
  10.         unlink($fullpath);
  11.     }
  12.     $fp = fopen($fullpath,'x');
  13.     fwrite($fp, $rawdata);
  14.     fclose($fp);
  15. }

Another Problem Solved :-)

Bookmark this Post
Add 'PHP Save Images Using cURL' to Del.icio.usAdd 'PHP Save Images Using cURL' to diggAdd 'PHP Save Images Using cURL' to FURLAdd 'PHP Save Images Using cURL' to blinklistAdd 'PHP Save Images Using cURL' to redditAdd 'PHP Save Images Using cURL' to Feed Me LinksAdd 'PHP Save Images Using cURL' to TechnoratiAdd 'PHP Save Images Using cURL' to Yahoo My WebAdd 'PHP Save Images Using cURL' to NewsvineAdd 'PHP Save Images Using cURL' to SocializerAdd 'PHP Save Images Using cURL' to Ma.gnoliaAdd 'PHP Save Images Using cURL' to Stumble UponAdd 'PHP Save Images Using cURL' to Google BookmarksAdd 'PHP Save Images Using cURL' to RawSugarAdd 'PHP Save Images Using cURL' to SquidooAdd 'PHP Save Images Using cURL' to SpurlAdd 'PHP Save Images Using cURL' to BlinkBitsAdd 'PHP Save Images Using cURL' to NetvouzAdd 'PHP Save Images Using cURL' to RojoAdd 'PHP Save Images Using cURL' to BlogmarksAdd 'PHP Save Images Using cURL' to ShadowsAdd 'PHP Save Images Using cURL' to Co.mments
Add 'PHP Save Images Using cURL' to ScuttleAdd 'PHP Save Images Using cURL' to BloglinesAdd 'PHP Save Images Using cURL' to TailrankAdd 'PHP Save Images Using cURL' to SegnaloAdd 'PHP Save Images Using cURL' to OKnotizieAdd 'PHP Save Images Using cURL' to NetscapeAdd 'PHP Save Images Using cURL' to Bookmark.itAdd 'PHP Save Images Using cURL' to AskAdd 'PHP Save Images Using cURL' to SmarkingAdd 'PHP Save Images Using cURL' to LinkagogoAdd 'PHP Save Images Using cURL' to DeliriousAdd 'PHP Save Images Using cURL' to SocialdustAdd 'PHP Save Images Using cURL' to Live-MSNAdd 'PHP Save Images Using cURL' to SlashDotAdd 'PHP Save Images Using cURL' to SphinnAdd 'PHP Save Images Using cURL' to DiggitaAdd 'PHP Save Images Using cURL' to SeotribuAdd 'PHP Save Images Using cURL' to FaceBookAdd 'PHP Save Images Using cURL' to UpnewsAdd 'PHP Save Images Using cURL' to WikioAdd 'PHP Save Images Using cURL' to Social Bookmarking Reloaded

Feed | Respond | Trackback

Leave a Reply

  • RSS Feed
  • Categories

    • apache
    • barcode
    • creloaded
    • curl
    • customer services
    • debugging
    • ecommerce
    • email
    • excel
    • firefox
    • flash
    • gd
    • graphs
    • hosting
    • icecat
    • internet news
    • javascript
    • link building
    • linux
    • magento
    • management
    • mod_rewrite
    • mysql
    • oscommerce
    • php
    • plesk
    • product catalogue
    • product feed
    • programming
    • regular expressions
    • scraping
    • search engine optimisation
    • spidering
    • ubuntu
    • web design
    • web development
    • Windows
    • xampp
    • zip
  • Archives

    • August 2008
    • July 2008
    • June 2008
    • May 2008
    • April 2008
    • March 2008
    • February 2008
  • Tags

    addons advanced adverts blackhat blocking css curl development directories find firefox google hosts file html javascript keywords links msn mysql myths operators oscommerce paid links paid placement performance php ppc reciprocal linking replace screen scraping security seo serp speed spider spidering tuning user friendly vista web web design web developer
  • Random Posts

    • MySQL Add Column if Not Exists - PHP Function
    • MySQL DB Admin GUI for Windows / XAMPP
    • osCommerce Contribution Released: Server Migration Synchronisation
    • Meta Title Tag and SEO
    • Populating osCommerce and other Ecommerce Platforms
    • Product Feed Integration and Scraping Products from Supplier Web Sites
    • PHP Cached Download Function
    • MySQL Copy Table from One Database to Another
    • ICECat Integration with osCommerce, Magento etc
    • 10 SEO Myths

Edmonds Commerce related questions? Send us a message or call us on 0844 357 0201.

Freelance PHP Web Design UK Commercial Web Design