2014-03-01 72 views
0

我有一个现有的脚本,我试图修改而不是从PC上传文件来上传,而是添加一个有问题的图片的网址。我一直在尝试使用获取文件函数,我可以使用它从url抓取文件并上传到服务器,但我希望它捕获该文件并传递到现有脚本的其余部分以完成调整大小等。从url上传图片

见下....

$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); 

回答

0

变化

$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); 

到:

$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);