localhost에서 작동하는 Apache Server를 사용하고 있습니다. PHP를 모르므로 w3schools 사이트의 코드를 시도했지만 제대로 작동하지 않습니다. 여기 PHP localhost에 파일 업로드
는 HTML 코드입니다 :<!DOCTYPE html>
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
PHP 코드 :
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
echo $target_file;
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
?>
는 PHP 코드의 시작 부분에 echo 명령은 단지 "업로드 /"그래서 나는 $를 추측 반환 _ 파일이 제대로 작동하지 않습니다.
EDIT2 내가 XAMPP 이번에 아파치를 다시 설치하고 난 코드에 더 이상 문제가 없다하지만 내 "업로드"에 업로드 어떤 파일이 아직 없다 (이것은 "파일은 이미지입니다"출력) 폴더. 내 "업로드"폴더가 localhost의 웹 페이지와 같은 폴더에 있습니다.
기본 php.ini (file_uploads = on)를 사용하고 있습니다. 다른 디렉토리에서 다른 크기의 다른 파일을 시도했지만 지금까지 성공하지 못했습니다.
작업중인 디렉토리에'uploads' 폴더가 생성 되었습니까? – Sree
그럼 뭐가 문제 야? – user1234
마지막 문장을 편집했습니다. PHP 코드 시작 부분의 echo 명령은 "uploads /"만 반환하므로 $ _FILES가 제대로 작동하지 않습니다. – oro777