Api 如何将代码点火器中的上传路径设置为url?
你好。。。。 我上传代码点火器中的图像时遇到问题。 我使用codeigniter作为后端。 代码如下所示:Api 如何将代码点火器中的上传路径设置为url?,api,codeigniter,file-upload,Api,Codeigniter,File Upload,你好。。。。 我上传代码点火器中的图像时遇到问题。 我使用codeigniter作为后端。 代码如下所示: public function upload_image_post() { if ($_FILES['image']) { $name = $_FILES['image']['name']; $this->load->library('upload', array( 'overwrite' => FALSE,
public function upload_image_post()
{
if ($_FILES['image']) {
$name = $_FILES['image']['name'];
$this->load->library('upload', array(
'overwrite' => FALSE,
'upload_path' => FCPATH . 'assets/public/image/news',
'max_size' => '2097152',
'allowed_types' => 'png|jpg|gif|jpeg',
));
if (!$this->upload->do_upload('image')) {
return $this->response([
'status' => false,
'message' => 'fail 1'
], 500);
} else {
$upload = $this->upload->data();
return $this->response([
'status' => true,
'message' => 'success',
'data' => $upload,
], 200);
}
} else {
return $this->response([
'status' => false,
'message' => 'fail 2'
], 500);
}
}
当我在localhost中使用它时,上传图像是成功的。但当我部署它时,它失败了,并显示消息“fail1”
如何设置上载路径,使其可以指向我想要的任何url???如果正在本地主机上上载,则您的逻辑可能是正确的。请尝试以下操作,看看这是否有帮助
assets/public/image/news/
您可以为
'message'=>$this->upload->display_errors()
更改'message'=>'fail 1'
?这可以让您了解上传失败的原因。执行此操作时,请检查上载目录是否存在,是否具有写入权限(请尝试将其修改为775,然后重试),并且您的PHP是否可以访问该目录process@KUMAR很抱歉,如果您正在查找anwser,则仍会延迟重播。如果您提供的字符串路径分别可写,则此函数将返回true或false。路径可以是文件或目录的路径。你可以在网站上详细阅读<代码>https://www.php.net/is_writable
<?php if(is_writable(base_url('assets/public/image/news/'))){
echo 'writable';
}
else { echo (base_url('assets/public/image/news/'). ' ' ."is not writable");} ?>