现在我已经尝试了大部分已经阅读过的修补程序,其中大多数都提到了APPPATH,base_url(),真实路径等等,但我真的不知道为什么所有修复都不起作用,对我有用的是,我使用的是实际路径,而不是网址,而是使用C:\ xampp \ htdocs ... blah blah blah ...现在我读了一个网址,网址和目录不是同样的事情..并且upload_path只接受目录路径,我的意思是服务器上的uploads文件夹的实际位置而不是URL ..现在我的问题是如何APPPATH不起作用。正如我所知道的实际目录路径。但当我试图显示它只返回“../applicaiton/”什么是在upload.php上的$ config ['upload_path']上使用的最佳路径,特别是当它部署到实际的服务器时它是真的很麻烦找到你的上传文件夹的目录路径,注意我不使用initialize()方法我把我的配置放在config / upload.php
编辑:
我在一个单独的文件中有这个... upload.php
<?php
$config['upload_path'] ='./uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '5000';
$config['max_width'] = '1600';
$config['max_height'] = '1200';
这是我的控制器
if($this->upload->do_upload('image'))
{
//Did something here
}
else
{
//Did something for errors like display_errors()
}
并且最终结果显示“上传路径似乎无效” 我也尝试过这些代码
试验1:
$config['upload_path'] ='./uploads/';
试验2:
$config['upload_path'] ='uploads/';
试验3:
$config['upload_path'] ='/admin/assets/uploads/';
试验4:
$config['upload_path'] ='./admin/assets/uploads/';
试验5:
$config['upload_path'] ='admin/assets/uploads/';
唯一有效的是这个
$config['upload_path'] ='C:\xampp\htdocs\practice\admin.abcgencon\admin\assets\uploads'';
并且使用最后一部分作为路径有点凌乱所以我也试过APPPATH
但是它也不起作用它也显示“../application”..
正如@cryptic所说,我已发布此代码段。
答案 0 :(得分:14)
问题,您分别尝试realpath
和APPPATH
了吗?
在Codeigniter中APPPATH
指向应用程序文件夹
示例 :(将您的文件夹放在应用程序文件夹之外,只是说如果您没有这样做)让我们说我们要放置名为 images
所以您需要做的是合并realpath(
)和APPPATH
$image_path = realpath(APPPATH . '../images');
并将其传递给您的配置
$config['upload_path'] = $image_path;
答案 1 :(得分:1)
创建文件上传目录,说上传到应用程序目录之外或CI的根目录,并按如下方式设置上传路径: -
$config['upload_path'] = realpath(FCPATH.'uploads');
FCPATH:存在index.php的前端控制器的路径(CI的根目录)
以上代码在服务器和本地运行。
答案 2 :(得分:0)
这是在CI
中完成文件上传的方式$cat_image_name = $_FILES["cat_image"]["name"] ;
//file uploading params
$config['upload_path'] = './uploaded_files/categories';
$config['allowed_types'] = 'gif|jpg|png';
$config['file_name'] = $image_id."_ipad";
$config['remove_spaces'] = TRUE;
//Loading Library - File Uploading
$this->load->library('upload', $config);
//Upload the image(Ipad)
if (!empty($cat_image_name))
{
$this->upload->do_upload('cat_image');
$data = array('upload_data' => $this->upload->data());
$category_image_ipad = $data['upload_data']['file_name'];
$img_extension = $data['upload_data']['file_ext'];
}
答案 3 :(得分:0)
试试这个
$config['upload_path'] = '../uploads/;
它对我来说非常好用
答案 4 :(得分:0)
使用它:
$config['upload_path'] = $_SERVER['DOCUMENT_ROOT']."/uploads/";
//$this->config->item('upload_path');
答案 5 :(得分:0)
文件上传需要多部分表单。为此,您必须包含表单助手。
转到配置文件夹,点击自动加载并找到{
"data": null,
"errors": [
{
"message": "Validation error of type FieldUndefined: Field 'id' in type 'ContentUnion' is undefined @ 'content/id'",
"locations": [
{
"line": 1,
"column": 26
}
],
"description": "Field 'id' in type 'ContentUnion' is undefined",
"validationErrorType": "FieldUndefined",
"queryPath": [
"content",
"id"
],
"errorType": "ValidationError",
"path": null,
"extensions": null
}
],
"extensions": null,
"dataPresent": false
}
,然后输入“表格”#39; :
$autoload['helper'] = array();
控制器:
$ config = array(
$autoload['helper'] = array('form');
代表型号:
'upload_path' => "./assets/",
'allowed_types' => "gif|jpg|png|jpeg",
'overwrite' => TRUE,
'max_size' => "2048000",
'max_height' => "768",
'max_width' => "1024"
);
$this->load->library('upload', $config);
if(!$this->upload->do_upload()){
$errors = array('error' => $this->upload->display_errors());
$post_image = 'noimage.jpg';
} else {
$data = array('upload_data' => $this->upload->data());
$post_image = $_FILES['userfile']['name'];
}
$this->user_model->create_photo($post_image);
redirect('');
}
答案 6 :(得分:0)
在Windows和Windows上测试过Linux操作系统:
$path = realpath(".");
$path .= "/uploads/profile_images";
此处uploads是root上的uploads目录。
答案 7 :(得分:-1)
这很简单:
只需将你的所有$ config复制到名为upload.php的新php文件中,并将其放在cofig文件夹中。
你的路径会正常工作。
这是upload.php文件内容:
<?php
$config['upload_path'] = site_url().'uploads';
$config['allowed_types'] = 'gif|jpg|png|jpeg|html|pdf';
$config['max_size'] = 0;
$config['max_width'] = 0;
$config['max_height'] = 0;
$config['file_ext_tolower'] = TRUE;
$config['overwrite'] = FALSE;
$config['max_filename'] = 0;
$config['encrypt_name'] = TRUE;
$config['remove_spaces'] = TRUE;
$config['detect_mime'] = TRUE;
$config['mod_mime_fix'] = TRUE;
?>
但是请在upload_file控制器中保留$ config数据。例如:
public function do_upload(){
$config['upload_path'] = 'uploads';
$config['allowed_types'] = 'gif|jpg|png|jpeg|html|pdf';
$config['max_size'] = 0;
$config['max_width'] = 0;
$config['max_height'] = 0;
$config['file_ext_tolower'] = TRUE;
$config['overwrite'] = FALSE;
$config['max_filename'] = 0;
$config['encrypt_name'] = TRUE;
$config['remove_spaces'] = TRUE;
$config['detect_mime'] = TRUE;
$config['mod_mime_fix'] = TRUE;
//Alternately you can set preferences by calling the initialize function. Useful if you auto-load the class:
$this->upload->initialize($config);
if (!$this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
很简单......