【问题标题】:upload an image from url从 url 上传图片
【发布时间】:2014-03-01 23:47:23
【问题描述】:

我有一个现有的脚本,我正在尝试修改它,而不是从 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);

【问题讨论】:

    标签: php url file-upload upload


    【解决方案1】:

    改变

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

    【讨论】:

      猜你喜欢
      • 2017-07-16
      • 2021-07-19
      • 1970-01-01
      • 1970-01-01
      • 2019-02-16
      • 1970-01-01
      • 2017-06-02
      • 2017-04-08
      • 1970-01-01
      相关资源
      最近更新 更多