Home / Tips / Programming languages / Scripting languages / PHP / Storing an image from URL in a file using PHP

Storing an image from URL in a file using PHP

PHP
 
PHP
  • Currently 0 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Rating: 0/5 (0 votes cast)

Thank you for rating!

You have already rated this page, you can only rate it once!

Your rating has been changed, thanks for rating!

Log in or create a user account to rate this page.


It can be simply done by two PHP functions file_put_contents and file_get_contents.

$urlToImage = 'http://www.example.com/image.gif';
$pathToStore = '/my_folder/my_image.gif';
file_put_contents( $pathToStore, file_get_contents( $urlToImage ) );

It can work if allow_url_fopen configuration directive is set as true.


 

Read also

What is PHP?

What is PHP?

Classes and objects in PHP

Classes and objects in PHP

How to access classes and objects in PHP

How to access classes and objects in PHP

Discussion (total 1 comments)

ShawnLam
January 22, 2017 at 02:14 pm
Christmas Piano
Christmas Background Music
Perfect instrumental background music for romantic and sentimental films, presenting your business, new products or your company in general with an optimistic and motivational touch.
Visit site: https://audiojungle.net/item/christmas-piano/19056234/
Twitter @esif22 https://twitter.com/esif22/status/805286803875958784

Post comment

basicuse.net
html5_css
106160485398655174790

Quick navigation

General navigation