アップロードするファイルを取得する際に問題が発生しました。 です。それはすべてを実行しますが、ファイルをアップロードしません。ただ さんの言葉:PHPでファイルをアップロードすることができません
ファイルに問題がありました。ここで
私のコードは次のとおりです。助けてくれてありがとう!
P.S.サイズは 問題ではないので、私がアップロードしようとしたファイルが11キロバイト大きいです。また、許可は問題ではありません。
<p>The file must be an image and less than 2 MB.</p>
<form action="filerupp.php" method="post" enctype="multipart/form-data">
<p>Choose file:<br/>
<input type="file" name="fileToUpload" id="fileToUpload"><br/>
<input type="submit" value="Upload image" name="submit"></p>
</form>
<p>Files are <a href='pictures'>here</a>.</p>
そして、ここに私のPHPコードです:
$target_dir = "pictures/";
$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 "<p>The File is an image" . $check["mime"] . ".<br/>";
$uploadOk = 1;
} else {
echo "<p>The File is not an image.<br/>";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "<p>Sorry, the file already exists.<br/>";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, the file är för stor.<br/>";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif") {
echo "Sorry, only JPG, JPEG, PNG & GIF.<br/>";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file cannot be uploaded.</p>";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "<p>The file ". basename($_FILES["fileToUpload"]["name"]). " has been uploaded and is <a href='pictures'>here</a>.</p>";
} else {
echo "<p>Sorry, there was something wrong with your file.</p>";
}
}
http://php.net/manual/en/features.file-upload.post-method.phpこのリンクをたどるか、画像をアップロードするフォルダの権限を確認することができるフォルダ – urfusion
の許可を確認してください。解決しない場合は私に連絡してください。 skype:harryr891 –
これはLinuxかWindowsか? – infinigrove