일 때 서버에 이미지 업로드가 작동하지 않습니다.이 스크립트를 사용하여 .jpg & .png 유형의 이미지를 서버 및 데이터베이스에 업로드하지만 .jpeg 또는 .JPG의 경우에는이 스크립트를 사용하지 않습니다. 올바른 확장자를 가진 올바른 디렉토리에 파일을 배치하는 대신에 /galleri/uploads/a4b7c7fb0de9c561110c2279f24ec820jpeg.php 파일을 자동으로 .php 끝에 추가합니다..jpeg 유형이
난 할 노력하고 봤는데 그에서 제외
내가이 경우에 사용할 수있는 더 나은 자르기 도구가 ..이 라인if ($type == 'image/jpeg') { $filetype = '.jpeg'; } else { $filetype = str_replace('image/', '', $type); }
if ($type == 'image/jpeg') { $filetype = '.JPG'; } else { $filetype = str_replace('image/', '', $type); }
하지만 사용에
추가하는 것입니다 그렇게 발전하지 않았습니까?이 전체 스크립트입니다
if(isset($_POST['addmedia'])) {
$mediatype = escape(striptags($_POST['mediatype']));
$title = escape(striptags($_POST['title']));
$video = escape(striptags($_POST['medialink']));
$date = date('Y-m-d');
if ($mediatype === 'img') {
if(!isset($_POST['p'])) { $_POST['p']= 0; }
if($_POST['p'] == 1) {
$name = $_FILES['image']['name'];
$temp = $_FILES['image']['tmp_name'];
$type = $_FILES['image']['type'];
$size = $_FILES['image']['size'];
if ($type == 'image/jpeg') { $filetype = '.jpg'; } else { $filetype = str_replace('image/', '', $type); }
if ($type == 'image/png') { $filetype = '.png'; } else { $filetype = str_replace('image/', '', $type); }
$path = md5(rand(0, 1000) . rand(0, 1000) . rand(0, 1000) . rand(0, 1000)) . $filetype;
$thumb_path = md5(rand(0, 1000) . rand(0, 1000) . rand(0, 1000) . rand(0, 1000)) . $filetype;
$size2 = getimagesize ($temp);
$width = $size2[0];
$height = $size2[1];
$maxwidth = 1281;
$maxheight = 751;
$allowed = array('image/jpeg', 'image/png');
if(in_array($type, $allowed)) {
if($width < $maxwidth && $height < $maxheight) {
if($size < 10485760) {
if($width == $height) { $case = 1;} // Square form
if($width > $height) { $case = 2;} // Lying form
if($width < $height) { $case = 3;} // Standing form
switch($case) {
case 1:
$newwidth = 280;
$newheight = 150;
break;
case 2:
$newheight = 150;
$ratio = $newheight/$height;
$newwidth = round($width * $ratio);
break;
case 3:
$newwidth = 280;
$ratio = $newwidth/$width;
$newheight = round($height * $ratio);
break;
}
switch($type) {
case 'image/jpeg':
$img = imagecreatefromjpeg($temp);
$thumb = imagecreatetruecolor($newwidth, $newheight);
imagecopyresized($thumb, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb, $_SERVER['DOCUMENT_ROOT'] . "/galleri/uploads/thumbs/" . $thumb_path);
break;
case 'image/png':
$img = imagecreatefrompng($temp);
$thumb = imagecreatetruecolor($newwidth, $newheight);
imagecopyresized($thumb, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagepng($thumb, $_SERVER['DOCUMENT_ROOT'] . "/galleri/uploads/thumbs/" . $thumb_path);
break;
}
move_uploaded_file($temp, $_SERVER['DOCUMENT_ROOT'] . "/galleri/uploads/" . $path);
$addimg = "INSERT INTO uploads (`type`, `title`, `src`, `thumb`, `date`) VALUES ('$mediatype', '$title', '$path', '$thumb_path', '$date')";
if ($add_img = $db_connect->query($addimg)) {}
echo 'Din bild har laddats upp!';
header("Location: " . $_SERVER['HTTP_REFERER']);
} else {
echo '10MB';
}
} else {
echo 'To big in size';
}
} else {
echo '.jpg, .jpeg, .png!';
}
}
} else if ($mediatype === 'vid') {
$name = $_FILES['image']['name'];
$temp = $_FILES['image']['tmp_name'];
$size = $_FILES['image']['size'];
$thumb_path = md5(rand(0, 1000) . rand(0, 1000) . rand(0, 1000) . rand(0, 1000)) . '.jpg';
move_uploaded_file($temp, $_SERVER['DOCUMENT_ROOT'] . "/galleri/uploads/thumbs/" . $thumb_path);
$addvid = "INSERT INTO uploads (`type`, `title`, `thumb`, `videolink`, `date`) VALUES ('$mediatype', '$title', '$thumb_path', '$video', '$date')";
if ($add_vid = $db_connect->query($addvid)) {}
echo 'Video uploaded';
header("Location: " . $_SERVER['HTTP_REFERER']);
}
}
를,'이미지 허용되지 않은 우리에게 그 결과를 말해? – akmozo
@akmozo .png 형식을 .jpg 형식으로 제거했을 때 한 가지 사실을 눈치 챘습니다. .JPG가 제대로 작동했습니다. 이것은 이상합니다. – Montague
잘못된 조건 때문입니다. 나는 대답을하고, 한 번보세요. – akmozo