0
현재 사용자가 음악을 업로드 할 수있는 웹 사이트를 개발 중입니다. 표시 할 다양한 장르를 설정할 수 있습니다. 이제는 특정 파일에 대한 업로드가 실패하는 경우가 종종 있습니다. 오류가 표시되지 않습니다. 대부분의 파일에서 업로드가 작동하기 때문에 권한 오류가 아닙니다. 나는 이미 많은 것을 둘러 보았고 많은 것들을 시도했지만 아무 것도 나를 위해 일하지 않았다.PHP 파일 업로드 문제
HTML 당신은 정확한 문제를 찾기 위해 파일 업로드 오류를 볼 필요가
<?php
/**
* Created by IntelliJ IDEA.
* User: Marc
* Date: 04.12.2017
* Time: 20:07
*/
require 'db.php';
$target_dir = "uploadedmusic/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$filename=$_FILES["fileToUpload"]['name'];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$genre = $_POST["Genre"];
$successfull = false;
if(isset($_POST["submit"])) {
// Check extensions
if ($ext != "mp3" && $ext != "wav") {
echo "Sorry, only MP3 & WAV files are allowed.";
$uploadOk = 0;
}
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)) {
$hash = md5_file("uploadedmusic/".$filename);
//echo "The file " . basename($_FILES["fileToUpload"]["name"]) . " has been uploaded.";
$sql = "INSERT INTO `music` (`id`, `filename`, `genre`, `uploaded`, `hash`) VALUES (NULL, '$filename', '$genre', CURRENT_TIMESTAMP, '$hash')";
$conn->query($sql);
$successfull = true;
} else {
$successfull = false;
}
}
}
?>
<html>
<head>
<title>Upload Music</title>
</head>
<body>
<div style="text-align: center;">
<img src="logo.png">
<h1>Please wait...</h1>
<p style="font-size: 35px;">
<?php
if ($successfull == true) {
echo "Successfully uploaded ". basename($_FILES["fileToUpload"]["name"])."! Use the search to find it!";
}
else {
echo "Sorry, there was an error uploading your file. Check for potential invalid characters like() or - in your filename!";
}
?>
</p>
<a style="font-size: 35px" href="main.php">Start listening!</a>
</div>
</body>
</html>
확인 파일 업로드 크기 제한 –
16메가바이트에 그것의 세트를 업로드 오류를 확인하는 조건을 추가해야합니다. –
업로드하기 전에 파일 크기를 확인하고 오류를 발생시켜 문제의 원인을 확인하십시오. https://stackoverflow.com/questions/5438060/showing-all-errors-and-warnings –