2016-12-29 26 views
-1

イメージをファイルを使用してファイルにアップロードします。私はコードを簡素化し続けますが、それでも動作しません。私は何が間違っているか把握したらパラメータを追加します。ここに私のファイルupload.phpイメージをファイルにアップロードする

<html> 
<body> 

<form action="upload.php" method="post" enctype="multipart/form-data"> 
    Select image to upload: 
    <input type="file" name="upload" id="upload"> 
    <input type="submit" value="Upload Image" name="submit"> 
</form> 

</body> 
</html> 

<?php 
if(isset($_POST["submit"])) { 
$pathway= "uploads/"; 
$target_file = $pathway . basename($_FILES["upload"]["name"]); 
    if (move_uploaded_file($_FILES["upload"]["tmp_name"], $target_file)) { 
     echo "The file ". basename($_FILES["upload"]["name"]). " has been uploaded."; 
    } 
} 
?> 

私は "uploads"というフォルダを作成しましたが、画像はそれに追加されません。

+0

アップロードフォルダの許可は何ですか? –

+0

許可ですか?私はGodaddyをホストとして使用しており、uploadsとupload.phpは同じディレクトリの下にあります。 – John

+0

http://php.net/manual/en/function.error-reporting.php –

答えて

0

まず、あなたのphp.ini ファイル

の属性file_uploads =上の第二、このコード

を参照してくださいあなたは

をしたいサイズにupload_max_filesizeで設定してくださいことを確認する必要があります

<?php 
$target_dir = "uploads/"; 
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); 
$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; 
    } 
    } 
// Check if file already exists 
if (file_exists($target_file)) { 
    echo "Sorry, file already exists."; 
    $uploadOk = 0; 
} 
// Check if $uploadOk is set to 0 by an error 
if ($uploadOk == 0) { 
    echo "Sorry, your file was not uploaded."; 
    // if everything is ok, try to upload file 
} else { 
     if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { 
     echo "The file ". basename($_FILES["fileToUpload"]["name"]). " has been uploaded."; 
} else { 
    echo "Sorry, there was an error uploading your file."; 
    } 
} 
?> 
関連する問題