【发布时间】:2020-04-12 15:33:32
【问题描述】:
我正在尝试使用 codeigniter 创建上传图像的缩略图(调整大小), 但是图片没有上传到服务器/文件夹,这是我的代码,我哪里出错了?
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();
}
}
【问题讨论】:
-
嗨。提供更多信息。您看到了什么错误,$_FILES['image'] 中有什么内容,Web 服务器日志中有什么内容等
-
表单是什么样子的?是否设置了 $_FILES['image'](在检查阶段)?
标签: php image codeigniter