【发布时间】:2021-09-07 13:47:04
【问题描述】:
我尝试将上传的文件保存在 2 个路径中,一个在文件夹内并包含 id,一个在文件夹外
这是我的代码:
private function _uploadImage()
{
$config['upload_path'] = './upload/'.$this->product_id;
$config['allowed_types'] = 'gif|jpg|png';
$config['file_name'] = $this->product_id;
$config['overwrite'] = true;
$config['max_size'] = 1024; // 1MB
$config['upload_path'] = './upload/product';
$config['allowed_types'] = 'gif|jpg|png';
$config['file_name'] = $this->product_id;
$config['overwrite'] = true;
$config['max_size'] = 1024; // 1MB
if (!is_dir('upload/'.$this->product_id)) {
mkdir('./upload/' . $this->product_id, 0777, TRUE);
}
$this->load->library('upload', $config);
if ($this->upload->do_upload('image')) {
return $this->upload->data("file_name");
}
return "default.jpg";
}
当我运行该代码时,结果卡住了
你能帮我看看有什么问题吗?
【问题讨论】:
-
您设置了 upload_path 键两次,它只是覆盖了自己。您需要完全处理两次上传,两个目录不同。
-
谢谢,兄弟你知道密码吗?
-
问题不是很清楚,但是为什么不把文件上传到第二个位置后直接复制呢? SO上有很多例子,例如stackoverflow.com/questions/5772769/…
标签: php codeigniter