이 코드로 이미지를 업로드 할 수 있지만 gif를 업로드하려고하면 오류가 발생합니다. 다음은 시도하는 방법이며 오류는 Error 2: ERROR upload file
입니다. 이것은 두 번째 IF 블록에 있습니다. 여기서 무엇이 잘못 될 수 있습니까?gif를 업로드하는 중 오류가 발생했습니다.
define('MAX_FILE_SIZE', 20000000000);
$permitted = array('image/jpeg', 'image/jpeg', 'image/png', 'image/gif');
if (isset($_POST['upload'])) {
$caption = $_POST['caption'];
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$category = $_POST['gif_cat'];
$ext = substr(strrchr($fileName, "."), 1);
// generate the random file name
$randName = md5(rand() * time());
// gif name with extension
$myFile = $randName . '.' . $ext;
// save gif path
$path = "../upload/gifs/" . $myFile;
if (in_array($fileType, $permitted) && $fileSize > 0
&& $fileSize <= MAX_FILE_SIZE) {
$result = move_uploaded_file($tmpName, $path);
if (!$result) {
echo "Error uploading gif file";
exit;
} else {
$db = new mysqli("localhost", "user", "pass", "table");
if (mysqli_connect_errno()) {
printf("Connect failed: %s<br/>", mysqli_connect_error());
}
mysqli_set_charset($db, "UTF8");
$query = "INSERT INTO gifs (caption, name, size, type, file_path, gif_cat) VALUES (?,?,?,?,?,?)";
$conn = $db->prepare($query);
if ($conn == TRUE) {
$conn->bind_param("ssisss",$caption, $myFile, $fileSize, $fileType, $path, $category);
if (!$conn->execute()) {
echo 'error insert';
} else {
echo "Gif {$_FILES['userfile']['name']} was successfully uploaded<br />
<a href='index.php'>Add another gif</a><br />";
exit;
}
} else {
die("Error 1: ERROR preparing Statement");
}
}
} else {
echo 'Error 2: ERROR upload file';
}
} else {
echo 'Error 3';
}
위해서 var_dump ($ _ FILES)
array (size=1)
'userfile' =>
array (size=5)
'name' => string 'azbRWYK_460sa.gif' (length=17)
'type' => string '' (length=0)
'tmp_name' => string '' (length=0)
'error' => int 1
'size' => int 0
UPDATE :
이 내가 < 1메가바이트의 GIF를 업로드 할 수 있었다 .. 1메가바이트보다 큰에서 .GIF 일어날 것입니다.
업데이트 2 : 이상한. 은 phpinfo에() 결과는
max_file_uploads 20 20
post_max_size 8M 8M
upload_max_filesize 2M 2M
하지만 내 php.ini 파일에서 나는이 차이가 어떻게
upload_max_filesize = 20M
post_max_size = 20M
max_file_uploads - I don't have this in php.ini?!
있나요? 그리고이 두 번째 php.ini 파일을 어디에서 찾을 수 있습니까?
UPDATE 3 :
좋아, 나는 아파치 폴더에있는 다른 php.ini 파일을 발견하고 내가 값을 변경 한 후 지금 작품이다. 나는 두 번째 php.ini 파일을 생각하지 못했습니다.
$ _FILES [ 'userfile'] [ 'type']을 인쇄하십시오. 허용되지 않을 수도 있습니다 – SajithNair
이것은 1MB보다 큰 .gif가있는 경우 발생합니다. 1MB 미만의 파일을 업로드 할 수있었습니다. – Goro