开发者

upload images having an url

开发者 https://www.devze.com 2023-04-08 11:05 出处:网络
I have a script to upload files to the server from your computer. It works fine and basically it\'s a

I have a script to upload files to the server from your computer. It works fine and basically it's a

<form enctype="multipart/form-data" action="post_img_upload.php?id='.$topicid.'" method="POST">
<input name="uploaded_file" type="file" />
<input type="submit" value="Subila" />

then, the post_img_upload.php starts like this:

 $target = "pics/"; 

$fileName = $target . $_FILES["uploaded_file"]["name"];           // The file name
$fileTmpLoc = $_FILES["uploaded_file"]["tmp_name"];     // 开发者_如何学编程File in the PHP tmp folder
$fileType = $_FILES["uploaded_file"]["type"];           // The type of file it is
$fileSize = $_FILES["uploaded_file"]["size"];           // File size in bytes
$fileErrorMsg = $_FILES["uploaded_file"]["error"];      // 0 for false... and 1 for true
$fileName = preg_replace('#[^a-z.0-9]#i', '', $fileName); // filter the $filename
$kaboom = explode(".", $fileName);                      // Split file name into an array using the dot
$fileExt = end($kaboom);    

Now I want to have the option to upload a file having an url address. Another form basically with

<form action="post_img_url_upload.php?id='.$topicid.'" method="POST">
<input name="url" type="text" size="100" /> 
<input type="submit" value="Copiar"/>

I would like to have post_img_url_upload.php similar to the post_img_upload.php. How can I approach that? How can I basically write

$fileName = $target . $_FILES["url"]["name"];

? Is it doable? Thanks!


AFAIK, no. The server would only get the url string, and then should try to fetch the image itself (instead of the image data being transferred from the client). You could google for "php external request" as there are a couple of ways to do it (cURL, remote file access, etc.).

0

精彩评论

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

关注公众号