2012-02-16 5 views
1

좋아, 아파치 htdocs의 폴더에 사진을 업로드하는 웹 페이지를 만들려고합니다. 그리고 ... 잘 ... 작동하지 않습니다 ... 저는 이것에 대한 자습서를 어디에서나 찾고 있으며 PHP에서 모든 작업을 수행해야합니다 (일부 HTML도 허용되지 않습니다). 여기 PHP (아파치 내) 폴더에 파일 업로드

는 다른 페이지 (upload_photos.php)는 파일을 업로드하는 중 오류가 발생했습니다 "라고에 도달하지만 일단 .... 내가 가진 무엇을이 시점이 바뀌지 이제

<p>Browse For a File on your computer to upload it!</p> 
<form enctype="multipart/form-data" action="upload_photos.php" method="POST"> 
<input type="hidden" name="MAX_FILE_SIZE" value="250000" /> 
Choose a file to upload: <input name="uploadedfile" type="file" /><br /> 
<input type="submit" value="Upload File" /> 
</form> 


     <?PHP  

    if ($uploadedfile_size >250000) 
    {$msg=$msg."Your uploaded file size is more than 250KB so please reduce the file size and then upload.<BR>"; 
    $file_upload="false";} 

    else{ 

    if (!($uploadedfile_type<>"image/jpeg" OR $userfile_type<>"image/tiff" OR $userfile_type<>"image/png")) 
    {$msg=$msg."Your uploaded file must be of JPG, PNG, or tiff. Other file types are not allowed<BR>"; 
    $file_upload="false";} 

    } 
     ?> 

     <!-- 
    •enctype="multipart/form-data" - Necessary for our PHP file to function properly. 
    •action="upload_photos.php" - The name of our PHP page that was created. 
    •method="POST" - Informs the browser that we want to send information to the server using POST. 
    •input type="hidden" name="MA... - Sets the maximum allowable file size, in bytes, that can be uploaded. This safety mechanism is easily bypassed and we will show a solid backup solution in PHP. We have set the max file size to 100KB in this example. 
    •input name="uploadedfile" - uploadedfile is how we will access the file in our PHP script. 

     --> 

</form> 

    </label> 
</form> 

입니다 , 다시 시도하십시오! "

<?php 

/* 
When the uploader.php file is executed, the uploaded file exists in a temporary storage area on the server. If the file is not moved to a different location it will be destroyed! To save our precious file we are going to need to make use of the $_FILES associative array. 

The $_FILES array is where PHP stores all the information about files. There are two elements of this array that we will need to understand for this example. 
•uploadedfile - uploadedfile is the reference we assigned in our HTML form. We will need this to tell the $_FILES array which file we want to play around with. 
•$_FILES['uploadedfile']['name'] - name contains the original path of the user uploaded file. 
•$_FILES['uploadedfile']['tmp_name'] - tmp_name contains the path to the temporary file that resides on the server. The file should exist on the server in a temporary directory with a temporary name. 

*/ 

// Where the file is going to be placed 
$target_path = "uploads/"; 

/* Add the original filename to our target path. 
Result is "uploads/filename.extension" */ 
$target_path = $target_path . basename($_FILES['uploadedfile']['name']); 


/* 
Now all we have to do is call the move_uploaded_file function and let PHP do its magic. The move_uploaded_file function needs to know 1) The path of the temporary file (check!) 2) The path where it is to be moved to (check!). 
*/ 

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


/* 

If the upload is successful, then you will see the text "The file filename has been uploaded". This is because move_uploaded_file returns true if the file was moved, and false if it had a problem. 

If there was a problem then the error message "There was an error uploading the file, please try again!" would be displayed. 

*/ 

?> 

제발 도와주세요, 제가 한 줄씩 살펴 봤는데 왜 그렇게하는지 모르겠습니다. 아마도 문법 오류 일 수도 있습니다. 나는 PHP에 아주 새로운 것이므로 의심하지 않는다. 어쨌든, 미리 감사드립니다.

+0

전체 서버 경로에 대한 $ target_path를 변경하십시오. –

+0

관련 Apache 설정은 무엇입니까? 아파치는 또한 파일 업로드의 종류와 크기에 제한을 둘 수있다. 그리고 아파치 에러 로그는 무엇을 말하고 있는가? –

+0

"PHP를 처음 접했습니다"--- ** 코드를 디버깅하는 방법을 배울 수있는 좋은 기회입니다. 아무도 당신을 위해 그 일을하지 않을 것이고 그것은 프로그래머로서의 평범한 직업입니다. – zerkms

답변

0

을 드롭 PHPinfo() 파일을 반환하고, 아파치가 CORE에서이 upload_max_filesize에 대한 내용을 확인할. 너무 낮게 설정되었을 수 있습니다.

혹시 훑어 본 경우에는 대상 디렉토리에 대한 권한을 확인하십시오. 목표 디렉토리가 775로 설정되었거나 대상 디렉토리가 쓰기 전에 단지 chmod이어야합니다.

0

변화 :

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

에 :

$test=move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path); 

if($test) { 
    echo "The file ". basename($_FILES['uploadedfile']['name']). 
    " has been uploaded"; 
} else{ 
    echo "There was an error uploading the file, please try again!"; 
    var_dump($test); 
} 

다음 우리가 그 위해서 var_dump를 알려 아래

+0

조금 그렇게 할 것입니다. 지금 내 노트북은 현재 업데이트를하고 있으며, 끝내 자마자 시도 할 것입니다. (방금 전에 많은 노트북을 가지고 있었기 때문에 많은 Windows 업데이트가 있습니다.) –

+0

그래, var_dump가 반환하는 유일한 방법은 "bool (false)"입니다. 그리고 나는 $ target_path를 전체 경로로 변경하려고 시도했다 ... 이제 chmod 권한도 시도 할 것이다. –