Question

I have an existing script that I'm trying to modify to rather than select a file from PC to upload but to add in a URL of the image in question. I've been trying to use the get file function and I can work it to grab the file from the url and upload to the server but I want it to capture the file and pass onto the remainder of the existing script to complete the resizing etc.

See below....

    $thumburl = "http://url of image file"; 
    $thumb = file_get_contents($thumburl);

    $space  = $_POST['thumb']['size'];
    move_uploaded_file($_POST['thumb']['tmp_name'], $config['TMP_DIR']. '/thumbs/' .$thumb);
   @chmod($config['TMP_DIR']. '/' .$thumb, 0644);
        $ff = $config['TMP_DIR']. '/thumbs/' .$thumb;
        $fd = $config['TMB_DIR']. '/' .$thid. '.jpg';
        createThumb($ff, $fd, $config['img_max_width'], $config['img_max_height']);
        copy($fd, $config['TMB_DIR']. '/1_' .$thid. '.jpg');
        copy($fd, $config['TMB_DIR']. '/2_' .$thid. '.jpg');
        copy($fd, $config['TMB_DIR']. '/3_' .$thid. '.jpg');
        @unlink($config['TMP_DIR']. '/thumbs/' .$thumb);
Was it helpful?

Solution

change

$thumburl = "http://url of image file"; 
$thumb = file_get_contents($thumburl);

$space  = $_POST['thumb']['size'];
move_uploaded_file($_POST['thumb']['tmp_name'], $config['TMP_DIR']. '/thumbs/' .$thumb);
@chmod($config['TMP_DIR']. '/' .$thumb, 0644);

to:

$thumburl = "http://url of image file"; 
$thumbContent = file_get_contents($thumburl);

$thumb = tempnam($config['TMP_DIR'] . '/thumbs/', 'FOO');
file_put_contents($config['TMP_DIR'] . '/thumbs/' . $thumb, $thumbContent);
@chmod($config['TMP_DIR'] . '/thumbs/' . $thumb, 0644);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top