0
다음 웹 사이트에서 이미지를 업로드 할 수있는 PHP 코드가 있습니다.일부 이미지를 업로드하는 중에 오류가 발생했습니다.
// 코드
global $objDB;
global $path_to_image_directory ;
global $path_to_thumbs_directory ;
$final_width_of_image = 500;
$path_to_image_directory = 'uploads/fullsized/';
$path_to_thumbs_directory = 'uploads/thumbs/';
$imagetitle="";
$mysqli = $objDB->connection;
if(isset($_FILES['uploaded']['name']))
{
if(preg_match('/[.](jpg)|(gif)|(png)$/', $_FILES['uploaded']['name'])) {
$filename = $_FILES['uploaded']['name'];
$source = $_FILES['uploaded']['tmp_name'];
$target = $path_to_image_directory . $filename;
move_uploaded_file($source, $target);
createThumbnail($filename);
$sql="INSERT INTO gallery(image)VALUES('$filename')";
$result=$objDB->query($sql);
if($result==1)
{
header("location:gallery.php?s_msg=Image added To gallery");
}
else
{
header("location:gallery.php?f_msg=Unable to Add Image");
}
}
else
{
header("location:gallery.php?f_msg=Unable to Add Image");
}
}
else
{
header("location:gallery.php?f_msg=Unable to Add Image");
}
function createThumbnail($filename) {
$path_to_image_directory="";
$path_to_thumbs_directory="";
$final_width_of_image="";
$path_to_image_directory = 'uploads/fullsized/';
$path_to_thumbs_directory = 'uploads/thumbs/';
$final_width_of_image = 400;
if(preg_match('/[.](jpg)$/', $filename)) {
$im = imagecreatefromjpeg($path_to_image_directory . $filename);
} else if (preg_match('/[.](gif)$/', $filename)) {
$im = imagecreatefromgif($path_to_image_directory . $filename);
} else if (preg_match('/[.](png)$/', $filename)) {
$im = imagecreatefrompng($path_to_image_directory . $filename);
}
$ox = imagesx($im);
$oy = imagesy($im);
$nx = $final_width_of_image;
$ny = floor($oy * ($final_width_of_image/$ox));
$nm = imagecreatetruecolor($nx, $ny);
imagecopyresized($nm, $im, 0,0,0,0,$nx,$ny,$ox,$oy);
if(!file_exists($path_to_thumbs_directory)) {
if(!mkdir($path_to_thumbs_directory)) {
die("There was a problem. Please try again!");
}
}
imagejpeg($nm, $path_to_thumbs_directory . $filename);
}
사용자가 1메가바이트
에 대해 크기의 이미지를 업로드하려고 어제까지 잘 작동하고 모든 및 던지고 오류 :
Premature end of JPEG file in db_gallery.php on line 64
fullsized/the_amazing_spider_man_2_movie-2048x1536.jpg' is not a valid JPEG file.
이미지 서버에 업로드되었지만 미리보기가 생성되지 않습니다. Pls 도움말.