【问题标题】:Not getting the correct path after uploading a file上传文件后没有得到正确的路径
【发布时间】:2017-02-25 14:02:28
【问题描述】:

我在服务器上上传一个文件并将其路径存储在 codeigniter 的数据库中,但是我在上传后我没有得到正确的路径

我使用的代码是

$config['upload_path']          = './uploads/';
$config['allowed_types']        = 'doc|docx|pdf';
$config['max_size']             = 100;
$config['max_width']            = 1024;
$config['max_height']           = 768;

$this->load->library('upload', $config);
$this->upload->do_upload('userfile');
$data = array('upload_data' => $this->upload->data());

$image_path = $data['upload_data']['full_path'];

我希望将我得到的路径保存在数据库中的 $image_path 中。

现在我得到的路径是这样的

/home/litehepn/public_html/project_name/uploads/xyz.docx

但我想要的路径是

project_name/uploads/xyz.docx

谁能告诉我如何获得正确的路径

【问题讨论】:

  • project_name 和uploads 都是已知的,为什么不直接将project_name/uploads/xyz.docx 保存在数据库中呢? (因为你上传后得到xyz.docx文件名)

标签: php mysql codeigniter file-upload


【解决方案1】:

这是正确的路径。因为您已将文件存储在该主目录中。但是您可以使用chop($url,"/home/litehepn/public_html/"); 来获取它。

【讨论】:

  • 你应该写 $url = "/home/litehepn/public_html/project_name/uploads/xyz.docx";然后 $new_url = Chop($url,"/home/litehepn/public_html/");
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-18
  • 2016-10-20
  • 1970-01-01
  • 2021-12-15
  • 2019-10-15
相关资源
最近更新 更多