大家好,我的网站有一个文件上传页面,可以上传一张或多张图片。这
问题是每当我上传文件时为我的图像创建拇指所以它应该创建
上传显示确认按摩但未创建的图像数量的拇指
图片的拇指。
实际上我已经从 PHP 学院下载了一个包
包含此文件 (create.thumb.php) 只是我调用了该函数及其上传文本
图像成功但未在 Thumbs 文件夹中创建图像的 Thumbs 是代码:
**create.thumb.php**
<?php
function create_thumb($directory, $image, $destination) {
$image_file = $image;
$image = $directory.$image;
if(file_exists($image)){
$source_size = getimagesize($image);
if($source_size !== false){
$thumb_width = (int)$width;
$thumb_height = (int)$height;
switch($source_size["mime"]){
case "image/jpeg" : $source = imagecreatefromjpeg($image); break;
case "image/png" : $source = imagecreatefrompng($image); break;
case "image/gif" : $source = imagecreatefromgif($image); break;
} $source_aspect = round(($source_size[0] / $source_size[1]), 1);
$thumb_aspect = round(($thumb_width / $thumb_height), 1);
if($source_aspect < $thumb_aspect){
$new_size = array($thumb_width, ($thumb_width / $source_size[0]) * $source_size[1]);
$source_pos = array(0, ($new_size[1] - $thumb_height) / 2);
} elseif($source_aspect > $thumb_aspect){
$new_size = array(($thumb_width / $source_size[1]) * $source_size[0], $thumb_height);
$source_pos = array(($new_size[0] - $thumb_width) / 2, 0);
} else {
$new_size = array($thumb_width, $thumb_height);
$source_pos = array(0, 0);
} if($new_size[0] < 1){
$new_size[0] = 1;
} if($new_size[1] < 1){
$new_size[1] = 1;
} $thumb = imagecreatetruecolor($thumb_width, $thumb_height);
imagecopyresampled($thumb, $source, 0, 0, $source_pos[0], $source_pos[1], $new_size[0], $new_size[1], $source_size[0], $source_size[1]);
switch($source_size["mime"]){
case "image/jpeg" : imagejpeg($thumb, $destination.$image_file); break;
case "image/png" : imagepng($thumb, $destination.$image_file); break;
case "image/gif" : imagegif($thumb, $destination.$image_file); break;
}
}
}
}
?>
-------------------------------------------------------------------------------------------------
**index.php**
<?php
require_once('db.php');
require_once('create.thumb.php');
@$PropertyName=$_POST['pname'];
@$PropertyStatus=$_POST['pstatus'];
@$PropertyID=$_POST['propertyid'];
if(isset($_FILES['file_upload']) && !empty($_FILES['file_upload']))
{
$propertyquery="INSERT INTO properties(PropertyID, PropertyName, PropertyStatus)
VALUES('$PropertyID', '$PropertyName', '$PropertyStatus')";
$propertyqueryrun=$connection->query($propertyquery);
$id = $connection->insert_id;
if(!$propertyqueryrun)
{
echo '<br><br> Property Insertion Failed';
}
else
{
echo '<br><br> The Property Information Insertion was Successfully <br><br>';
}
mkdir("upload/$PropertyID");
$files=$_FILES['file_upload'];
for($x = 0; $x < count($files['name']); $x++)
{
$name=$files['name'][$x];
$tmp_name=$files['tmp_name'][$x];
if(move_uploaded_file($tmp_name, "upload/$PropertyID/".$name))
{
$insert_id=$id;
**create_thumb('upload/$PropertyID/',$name,'thumbs/$PropertyID/');**
$imagequery="INSERT INTO propertyimages(PropertyImageID, ImageName, ImagePath) VALUES('$insert_id', '$name', 'upload/$PropertyID/$name')";
$imagequeryrun=$connection->query($imagequery);
echo 'Image '. $name .' Uploaded Successfully <br>';
}
else
{
echo 'YOU HAVE TO SELECT ONE PIC AT LEAST';
}
}
}
?>