开发者

Automatically get images masked by PHP and Query-String

I have access to some images that can be gathered like this:

http://www.example.com/imageGetter.php?a=0001

If I change the query-string a to 0002 I get the other image. It's thousands of images, and I'm attempting to get the images programatically (either by loading them in the browser, or by saving them to the disk).

Question: How do I get images stored like this programatically ?

I have two possible ways here here:

1) Using .NET, loading it (as a web-request), parsing the result (which is an image I c开发者_运维技巧an save, but can't get a real address, as it's gathered at run-time, not linked to me) and saving the image (which would be done via .net, using C#).

2) Copying it to memory (maybe in a java script image var) and putting it in an < img > tag. I've got the repeating routine to keep appending < img > tags, so I just have to load the image to an < img >.

All of this having in mind that I DO have access to those images, I could just save them all manually, I just don't want to, I'd like to save them automatically, as they change frequently.

If you have other ways for solving this, feel free to leave an answer, and I'll gladly try it out!

Note: done a quick search, but didn't find any similar questions, but I'm not entirely sure this isn't a dupe, because I may not know the exact terms of what I want. If it's a dupe, let me know, and I'll delete this question.


In PHP.

you could adapt code like this to accept all image types:

$remote_img = 'http://www.somwhere.com/images/image.jpg';
$img = imagecreatefromjpeg($remote_img);
$path = 'images/';
imagejpeg($img, $path);

use the php GD library to learn how to accept more file types

An alternative would be to use cURL.

function save_image($img,$fullpath){
    $ch = curl_init ($img);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
    $rawdata=curl_exec($ch);
    curl_close ($ch);
    if(file_exists($fullpath)){
        unlink($fullpath);
    }
    $fp = fopen($fullpath,'x');
    fwrite($fp, $rawdata);
    fclose($fp); 
} 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜