Saving image from PHP URL
If you have allow_url_fopen
set to true
:
$url = 'http://example.com/image.php';
$img = '/my/folder/flower.gif';
file_put_contents($img, file_get_contents($url));
Else use cURL:
$ch = curl_init('http://example.com/image.php');
$fp = fopen('/my/folder/flower.gif', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
How to save webpage with all styles and images similar to evernote?
Replace linked stylesheets with style blocks containing the CSS copied from the linked stylesheets. Replace image sources with data URLs.
How do you create an image of a web page in PHP?
You should get wkhtmltoimage
, which is very easy to utilize from within PHP:
exec("../wkhtmltoimage --crop-w 600 http://example.com/ output.png");
There are other options, and instead of --crop-w
or --width 600
it might be better to downscale it using GD or imagemagick afterwards.
Save webpage fully (with images, css, etc), better like web archive
I think to write your own, you can use curl and search for external urls, then recursively follow those. There may be a library out there.
Otherwise, you can use exec()
in php to run a command-line program. HTTrack does a good job at achiving websites:
http://www.httrack.com/html/fcguide.html
So, for example:
exec('httrack "http://www.all.net/" -O "/tmp/www.all.net" "+*.all.net/*" -v');
In addition, if you'd like to use wget
, I found a set of options that should work (allegedly as I haven't tried it):
wget \
--recursive \
--no-clobber \
--page-requisites \
--html-extension \
--convert-links \
--restrict-file-names=windows \
--domains example.com \
--no-parent \
www.example.com/directoryToArchive
Save image from url to local System in php
The problem is that the "images" you are using in the file_put_contents is not getting the path that where to save the file. try to make the images folder along with php file which having this code and see its working.
<?php
$imageUrl = 'https://cwsimages.ingramtest.com/cdsImages/imageloader?id=pBbFysOWRLJoSy4l4lbc+yLblU6JMuhKpze3XsQNO+njA3/XYRYbXSEYYsSqKXoiGD07duAyOSVXNUVLvxDqlMx15WtRQWJn3xC/twmM2s62tw+XgriCmEXBHawun03pQLBHXLuEQhNmCb8MC3ZMNH7pe5O76s18u/mgplf8YtU=';
@$rawImage = file_get_contents($imageUrl);
if($rawImage)
{
file_put_contents("images/".'dummy1.png',$rawImage);
echo 'Image Saved';
}
else
{
echo 'Error Occured';
}
?>
Capture the image in background and save in folder in PHP
You can achieve this by using below library.
Source: https://github.com/stil/gd-text
Wrote the script in PHP and run via terminal to create image in background.
PHP save image file
No need to create a GD resource, as someone else suggested.
$input = 'http://images.websnapr.com/?size=size&key=Y64Q44QLt12u&url=http://google.com';
$output = 'google.com.jpg';
file_put_contents($output, file_get_contents($input));
Note: this solution only works if you're setup to allow fopen access to URLs. If the solution above doesn't work, you'll have to use cURL.
Related Topics
How to Serve Documents from Outside the Web Root Using PHP
How to Get Whole and Decimal Part of a Number
PHP 7 Rc3: How to Install Missing MySQL Pdo
Could Not Open Input File: Composer.Phar
Laravel Eloquent Sort by Relation Table Column
Push Notifications from Server to User with PHP/Javascript
How to Access Service Container in Symfony2 Global Helper Function (Service)
PHP Get PDF File from Base64 Encoded Data String
Apply a Coupon Programmatically in Woocommerce
When to Use Index.PHP Instead of Index.Html
Get Last Executed Query in PHP Pdo
PHP - Check If the Page Run on Mobile or Desktop Browser
Remove Trailing Slash from String PHP
Strict Standards: Only Variables Should Be Assigned by Reference PHP 5.4