从URL上传图像作为文件


upload image as file from URL

使用此脚本"PHP和Jquery图像上传和裁剪":http://www.webmotionuk.com/php-jquery-image-upload-and-crop/我想上传的文件不是从本地,而是从URL。你知道我该怎么做吗?

我正试着像那样做

<form name="photo" action="test.php" method="post">
    <input type="hidden" name="zdj_tmp" value="E:'WebServ3'httpd'telebim'zdjecia'<? echo $select_zdjecie_2["id_4"]; ?>.jpg"/>
    <input type="hidden" name="zdj_name" value="<? echo $select_zdjecie_2["id_4"]; ?>.jpg"/>
    <input type="hidden" name="zdj_size" value="7340043"/>
    <input type="hidden" name="zdj_type" value="image/jpeg"/>               
    <input type="submit" name="upload" value="Upload" />
</form>

与php文件相比

$userfile_name = $_POST['zdj_name'];
$userfile_tmp = $_POST['zdj_tmp'];
$userfile_size = $_POST['zdj_size'];
$userfile_type = $_POST['zdj_type'];

但它不起作用。

有什么想法吗?

试试这个。

<form action="test.php" method="POST">
  <input type="text" name="fileURL" placeholder="URL to image">
  <input type="submit" name="upload" value="Upload files"/>
</form>

这是PHP

//Get the file from the URL. 
$content = file_get_contents($_POST['fileURL']);
//Open the file that exists in your root already
$fp = fopen("/location/to/save/image.jpg", "w");
//Copy the information into the existing image
fwrite($fp, $content);
fclose($fp);

这会从图像中获取信息,并将其复制(覆盖)到现有图像中,而现有图像只是一些无用的图像。

然后,您可以从根加载图像。

这不是最好的方法,因为你的原始图像会被打乱,并且只能使用一次,因为其他用户会更改它,还有其他更好的方法。但是,如果你的网站是一个非常不受欢迎的网站,而你只是想测试一些方法,这绝对是一种方法。只是不是最好的