현재 기본 미디어 파일 업로드 양식에 대한 자습서를 따르고 있습니다. 내 웹 사이트에 추가하려고했지만 항상 "파일을 업로드하는 동안 오류가 발생했습니다. 다시 시도하십시오!"라는 메시지가 나타납니다. 그것을 사용하여 이미지를 업로드하려고 할 때.
내 서버에 다음 html 파일을 넣었습니다.
<DOCTYPE! html>
<html>
<head>
</head>
<body>
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
</body>
</html>
그런 다음 다음과 같은 uploader.php 파일을 만들었습니다.
<?php
// 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']);
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!";
}
?>
이 파일들을 같은 디렉토리에 저장했습니다. 그런 다음 쓰기 가능한 uploads라는 또 다른 디렉터리를 만들었습니다.
이것이 작동하지 않는 이유는 무엇입니까?
편집 : 이제 최대 1MB 크기의 파일을 업로드 할 수 있지만 이보다 큰 파일은 업로드에 실패합니다. HTML 스크립트에서 볼 수 있듯이 최대 파일 크기를 10MB로 설정 했으므로 작동합니다. 왜 그렇지 않은지 아십니까?
작동합니다. 내 데스크톱을 확인했습니다.
변경 value="100000"
에value="1000000"
처럼
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
과,
$target_path = "uploads/";
MAX_FILE_SIZE (바이트로 측정) 숨겨진 필드는 파일 입력 필드 앞에 위치해야하고, 그 값은 PHP에서 허용하는 최대 파일 크기입니다.
자세한 정보를 보려면 파일 업로드를 클릭하십시오. -PHP Manual
사용자의 요구 사항 (그는 코멘트에서 물었다)
파일 이름에 time()
. 할 수있는 방법은 여러 가지가 있습니다. 그러나 이것은 당신이 사용할 수 있습니다.
$target_path = $target_path .time() .basename( $_FILES['uploadedfile']['name']);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다