2011-09-27 2 views
0

컴퓨터에서 서버로 파일을 업로드하는 스크립트가 있습니다. 그것은 잘 작동하고 기본적으로는 다음URL이있는 이미지 업로드

<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" /> 

의의 post_img_upload.php는 다음과 같이 시작합니다

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

지금 나는 URL 주소를 갖는 파일을 업로드 할 수있는 옵션을 갖고 싶어. 또 다른 형태는 기본적으로

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

와 나는 post_img_upload.php 유사 post_img_url_upload.php을하고 싶습니다. 어떻게 접근 할 수 있습니까? 기본적으로 쓸 수있는 방법은 무엇입니까?

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

? 그것은 가능합니까? 감사합니다.

+0

아니요,이 파일 입력을 사용할 수 없습니다. 사용자에게 텍스트 필드에 URL을 입력하도록 요청한 다음 PHP 스크립트에 제공된 URL을 가져와야합니다. –

답변

1

AFAIK, no. 서버는 URL 문자열 만 가져오고 클라이언트에서 전송 된 이미지 데이터 대신 이미지 자체를 가져와야합니다. 당신은 그것을 할 수있는 몇 가지 방법 (cURL, 원격 파일 액세스 등)로 "PHP 외부 요청"에 대한 Google 수 있습니다.