2016-09-26 2 views
0

내 서버에 파일 업로드에 대한 자습서를 진행했습니다. 스크립트가 작동하는 것처럼 보이지만 업로드 디렉토리를 보면 아무 것도 없습니다.PHP 파일 업로드 스크립트가 실패합니다.

<?php 

$file_result=""; 

if ($_FILES["file"]["error"] > 0) 
{ 
$file_result .= "No file uploaded or invalid file."; 
$file_result .= "Error code: ". $_FILES["file"]["error"]. "<br>"; 
} else { 

$file_result .= 
    "Upload: " . $_FILES["file"]["name"] . "<br>" . 
    "Type: " . $_FILES["file"]["type"] . "<br>" . 
    "Size: " . ($_FILES["file"]["size"]/1024) . " Kb<br>" ; 
    "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>"; 

    move_uploaded_file($_FILES["file"]["tmp_name"], 
    "full/path/on/server" . $_FILES["file"]["name"]); //Actual address removed 

    $file_result .= "File Upload Successful!"; 
} echo $file_result; 

?>` 

html로는 다음과 같다 :`업로드에 대한 코드를 다음

<form enctype="multipart/form-data" action="upload_file.php" method="post"> 
Browse Files:<br> 
    <input name="file" type="file" id="file" size="80"><br> 
    <input type="submit" id="u_button" name="u_button" Value = "Upload the File"> 
</form> 

`

+0

오류보고를 켜고 오류를 해결하는 시작, 행복 디버깅 . – Epodax

+0

대상 폴더에 쓰기 권한이 있습니까? – AkshayP

+0

enctype을 사용하지 않았습니다. 양식을

...로 확인하십시오. ... enctype – madankundu

답변

0

사용 :

if (Isset($_FILES["yourfilename"]["name"])) { 
    $uploadOk = 1; 
    $target_dir = "Upload/"; 
    --path 
    $tempname = basename($_FILES["yourfilename"]["name"]); 
    $target_file = $target_dir.basename($_FILES["yourfilename"]["name"]); 
    $imageFileType = pathinfo($target_file, PATHINFO_EXTENSION); 
    // Check if image file is a actual image or fake image 
    if ($tempname != "") { 
     if ($_FILES["yourfilename"]["size"] > 20000000) { 
      echo "Sorry, Maximum 20 mg.<br>"; 
      $uploadOk = 0; 
     } 
     if ($imageFileType != "doc" && $imageFileType != "docx" && $imageFileType != "txt") { 
      echo "Soory, Doc-Docx-Txt Only Format Sopport.<br>"; 
      $uploadOk = 0; 
     } 

     if (move_uploaded_file($_FILES["yourfilename"]["tmp_name"], $target_file); 
     } 
    } 
+0

*** 설명 *** 변경된 사항. –

관련 문제