Viewed   113 times

Possible Duplicate:
Saving image from PHP URL

I have an image as a url link from the 3rd party web thumb site (IE What I would like to do is run a script that takes the image and saves it in a directory on my server using php. How to do this? would I use File Write?



No need to create a GD resource, as someone else suggested.

$input = '';
$output = '';
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.

Thursday, September 1, 2022

Here's what worked best for me when trying to script this (in case anyone else comes across this like I did):

$ pecl -d php_suffix=5.6 install <package>
$ pecl uninstall -r <package>

$ pecl -d php_suffix=7.0 install <package>
$ pecl uninstall -r <package>

$ pecl -d php_suffix=7.1 install <package>
$ pecl uninstall -r <package>

The -d php_suffix=<version> piece allows you to set config values at run time vs pre-setting them with pecl config-set. The uninstall -r bit does not actually uninstall it (from the docs):

vagrant@homestead:~$ pecl help uninstall
pecl uninstall [options] [channel/]<package> ...
Uninstalls one or more PEAR packages.  More than one package may be
specified at once.  Prefix with channel name to uninstall from a
channel not in your default channel (

  -r, --register-only
        do not remove files, only register the packages as not installed

The uninstall line is necessary otherwise installing it will remove any previously installed version, even if it was for a different PHP version (ex: Installing an extension for PHP 7.0 would remove the 5.6 version if the package was still registered as installed).

Monday, December 12, 2022

Take a look at the exif_read_data() function within PHP.

Here is the official PHP documentation, and here's an example of it in use.

Sunday, December 4, 2022
public class EventMastersController : Controller
    private IHostingEnvironment _env; 

    public EventMastersController(IHostingEnvironment env)
        _env = env;

    public void AddFolderAndImage()
        var webRoot = _env.WebRootPath;
        var PathWithFolderName = System.IO.Path.Combine(webRoot, "MyFolder");

        if (!Directory.Exists(PathWithFolderName))
            // Try to create the directory.
            DirectoryInfo di = Directory.CreateDirectory(PathWithFolderName);

            string Base64String = eventMaster.BannerImage.Replace("data:image/png;base64,", "");

            byte[] bytes = Convert.FromBase64String(Base64String);

            Image image;
            using (MemoryStream ms = new MemoryStream(bytes))
                image = Image.FromStream(ms);

            image.Save(PathWithFolderName + "/ImageName.png");

Saturday, September 24, 2022

Never used any of those, but they look interesting..

Take a look at Gearman as well.. more overhead in systems like these but you get other cool stuff :) Guess it depends on your needs ..

Friday, November 11, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :