2013-06-01 3 views
0

OK 이렇게하면 관리자 제어판의 PHP를 통해 내 웹 서버에 이미지를 업로드 할 수 있습니다. 이제 파일 업 로더를 사용하여 이미지를 업로드하고 이미지가 호출 될 파일 이름에 텍스트 상자를 사용할 수 있기를 원합니다. 건배 : D사용자 정의를 사용하여 웹 서버에 파일 업로드

답변

1

사용 HTML의 표준 양식을

<form enctype="multipart/form-data" action="uploader.php" method="POST"> 
<input type="hidden" name="MAX_FILE_SIZE" value="100000" /> 
Filename: <input name="name" type="text" /> 
Choose a file to upload: <input name="uploadedfile" type="file" /><br /> 
<input type="submit" value="Upload File" /> 
</form> 

다음 uploader.php 파일 :

//get the data from the form 
$target_path = "uploads/"; 

$name= $_POST['name']; 

$target_path = $target_path . $name; 

//this is the script which uploads the file 
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { 
echo "The file ". basename($_FILES['uploadedfile']['name']). 
" has been uploaded as" . $name; 
} else{ 
echo "There was an error uploading the file, please try again!"; 
} 

당신이 그렇게 .. 파일은 이미지입니다 확인 할 수 있습니다 :

$max_size=20000; //in kb 
$allowedExts = array("gif", "jpeg", "jpg", "png"); 
$extension = end(explode(".", $_FILES["file"]["name"])); 
if ((($_FILES["file"]["type"] == "image/gif") 
|| ($_FILES["file"]["type"] == "image/jpeg") 
|| ($_FILES["file"]["type"] == "image/jpg") 
|| ($_FILES["file"]["type"] == "image/pjpeg") 
|| ($_FILES["file"]["type"] == "image/x-png") 
|| ($_FILES["file"]["type"] == "image/png")) 
&& ($_FILES["file"]["size"] < $max_size) 
&& in_array($extension, $allowedExts)) 
{ 

//here goes the script to upload the file!! 

}else{ 
echo"The file is not supported";} 
+0

[w3schools] (http://www.w3schools.com/php/php_file_upload.asp)에서 자세한 정보를 찾을 수 있습니다. – Anze

관련 문제