여러 이미지 업로드 스크립트가 있으며 이미지 크기를 조정하고 미리보기 이미지를 만듭니다. 일부 이상한 이유로 일부 이미지는 보이지 않습니다. 이 경우 이미지 크기가 작고 JPEG 형식 파일입니다. 웬일인지. 그것은 다른 이미지들과 완벽하게 작동합니다. 단일 파일에 동일한 스크립트를 사용하고 해당 이미지 파일을 업로드합니다. 도와주세요! 감사!PHP 다중 이미지 업로드 스크립트가 일부 이미지 파일을 업로드하지 않습니다.
<?php require_once("../includes/connection.php"); ?>
<?php require_once("../includes/functions.php"); ?>
<?php
$albumName = $_GET['album'];
$albumDate = $_GET['date'];
$albumId = $_GET['id'];
$upload_path = "/home/elevat17/public_html/images/gallery/"; //location
$images = $_FILES['userFile']['name'];
$temps = $_FILES['userFile']['tmp_name'];
$types = $_FILES['userFile']['type'];
$errors = $_FILES["userFile"]["error"];
if ($_FILES["userFile"]["name"]=="") {echo "You must choose a file to upload!";}
if(in_array("", $images)) {die('Select an image to upload.');}
else
{
for ($n=0; isset($images[$n]) && isset($temps[$n]) && isset($types[$n]) && isset($errors[$n]); $n++) {
if ((($types[$n] == "image/gif")
|| ($types[$n] == "image/jpeg")
|| ($types[$n] == "image/pjpeg")
|| ($types[$n] == "image/png")
|| ($types[$n] == "image/jpg")
|| ($types[$n] == "image/x-png")))
{
if ($errors[$n] > 0)
{
$content = "Return Code: " . $errors[$n] . "<br />";
}
else
{
$content = "Upload: " . $images[$n] . "<br />";
$content = "Type: " . $types[$n] . "<br />";
$content = "<br/><br/>";
if (file_exists($upload_path . $images[$n]))
{
die($images[$n].' already exists. Upload cancelled!');
}
else
{
$uploadedfile = $temps[$n];
$image = $images[$n];
$size = getimagesize($uploadedfile);
$type = $size['mime'];
$width = $size[0];
$height = $size[1];
if($height > '900' || $width > '600')
{
$newwidth=600; // NEW WIDTH
$newheight=($height/$width)*$newwidth;
$tmp=imagecreatetruecolor($newwidth,$newheight);
$filename = $upload_path.$image;
if($size[2] == IMAGETYPE_GIF)
{
$src = imagecreatefromgif($uploadedfile);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
imagegif($tmp,$filename,100);
}
elseif($size[2] == IMAGETYPE_JPEG)
{
$src = imagecreatefromjpeg($uploadedfile);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
imagejpeg($tmp,$filename,100);
}
elseif($size[2] == IMAGETYPE_PNG)
{
$src = imagecreatefrompng($uploadedfile);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
imagepng($tmp,$filename,9);
}
crop_img(75,75);
move_uploaded_file($uploadedfile, $filename);
imagedestroy($src);
imagedestroy($tmp);
}
else
{
}
$query = "INSERT INTO photos (photo_name, in_album) VALUES ('{$image}', $albumId)";
if (mysql_query($query)) {header("location: edit_album.php?id={$albumId}");}
}
}
}
else { $content = "Invalid file"; }
}
}
?>
<?php require("../includes/footer.php"); ?>
코드를보다 읽기 쉬운 방식으로 구성하십시오. – DaneSoul
이미지에 대한 자세한 정보를 제공하십시오. 크기, 너비, 높이, 파일 끝 – Sliq
@ChristianLavie 덕분에 나는 당신이 올바른 진술을했기 때문에 if 문 때문에 코드가 엉망인 이미지의 너비와 높이 때문에라고 생각합니다. 고쳤다. 건배 –