图像不会在代码点火器 PHP 中调整大小和上传



我正在尝试使用代码点火器创建上传图像的缩略图(调整大小(, 但是图片没有上传到服务器/文件夹,这是我的代码,我哪里出错了?

if (isset($_FILES['image'])) {
if (file_exists($_FILES['image']['tmp_name']) || is_uploaded_file($_FILES['image']['tmp_name'])) {
$filename         = time() . uniqid(rand()) . $_FILES['image']['name'];
move_uploaded_file($_FILES["image"]["tmp_name"], "vendorProfile/" . $filename);
$saveArr['image'] = $filename;
$this->load->library('image_lib');
$source_paths = base_url() . 'vendorProfile/' . $filename;
$source_path  = $_SERVER['DOCUMENT_ROOT'] . '/Profile/vendorProfile/' . $filename;
$target_path  = $_SERVER['DOCUMENT_ROOT'] . '/Profile/vendorProfile/thumb';
$config_manip = array(
'image_library'  => 'gd2',
'source_image'   => $source_path,
'new_image'      => $target_path,
'maintain_ratio' => TRUE,
'create_thumb'   => TRUE,
'thumb_marker'   => '_thumb',
'width'          => 150,
'height'         => 150
);
$this->load->library('image_lib', $config_manip);
if (!$this->image_lib->resize()) {
echo $this->image_lib->display_errors();
} else {
echo "image is uploaded";
}
$this->image_lib->clear();
} 
}       

你只需查看你在 $config_manip 数组上传递的文件路径,你需要在没有 Http 的情况下传递文件路径,或者 https PHP 不接受 Http。因此,如果在您的情况下,您的文件结构如下所示

-
application
system
image_folder <----

然后你只是像这样通过

$config_manip = array(
'image_library'  => 'gd2',
'source_image'   => './image_folder/'.$file_name,
'new_image'      => './thumb_folder/'.$target_path,
'maintain_ratio' => TRUE,
'create_thumb'   => TRUE,
'thumb_marker'   => '_thumb',
'width'          => 150,
'height'         => 150
);

如果您使用的是 ubuntu 服务器,则需要授予该文件夹上传文件/图像的权限。

if (!file_exists($target_path)) {
if (!mkdir($target_path, 0777, true)) {
chmod($target_path, 0777);
}
}

相关内容

  • 没有找到相关文章

最新更新