【问题标题】:PHP Codeigniter uploads failed with no errorsPHP Codeigniter 上传失败,没有错误
【发布时间】:2015-07-24 05:09:39
【问题描述】:

我想使用注册表单上传文件。我使用了 Codeigniter 的 File_Upload 库。但是文件没有上传到目的地,也没有出现错误。 这只是我代码的一部分(它们都非常庞大)

控制器(seeker_register.php):

public function submit(){
...
$this->load->model('mseeker_register');
$user_id = $this->mseeker_register->register($data);

查看(vseeker_register.php):

$attr = array("class" => 'form-horizontal seeker_register','id' => 'form-seeker-register');
echo form_open_multipart('seeker_register/submit',$attr);
...
<div class="col-sm-6 col-sm-offset-3">
<input name="Aks" type="file" class="fileinput" accept=".jpg, .jpeg">
</div>

模型(mseeker_register.php):

...
// Prepare Aks
$config = array(
    'upload_path' => './img/users',
    'allowed_types' => 'jpg|jpeg|JPG|JPEG',
    'max_size' => '200',
    'max_width' => '1024',
    'max_height' => '768');

$this->upload->initialize($config);
$this->upload->do_upload('Aks');

$this->upload->display_errors();
exit();
...

这是 $this->upload->data() 输出:

Array
(
    [file_name] => Clipboard-2.jpg
    [file_type] => image/jpeg
    [file_path] => D:/khayyamkar.ir/www/img/users/
    [full_path] => D:/khayyamkar.ir/www/img/users/Clipboard-2.jpg
    [raw_name] => Clipboard-2
    [orig_name] => 
    [client_name] => Clipboard-2.jpg
    [file_ext] => .jpg
    [file_size] => 156.42
    [is_image] => 1
    [image_width] => 
    [image_height] => 
    [image_type] => 
    [image_size_str] => 
)

【问题讨论】:

  • 检查文件夹的权限
  • 我在 XAMPP for Windows 上测试代码,用户是管理员。我有写的权限。
  • 如果您可以启用打印错误 error_reporting(-1); 您将遇到问题ini_set('display_errors', '开'); 就在你的页面标题后面

标签: php forms codeigniter file-upload


【解决方案1】:

当我扫描您的代码时,我意识到您无法查看错误。

要查看错误是什么,您需要使用var_dump()print_r() php 方法来查看错误是什么。

例如:

var_dump($this->upload->display_errors());

在您当前的代码中您需要更改:

$this->upload->display_errors();
exit();

到:

var_dump($this->upload->display_errors());
exit();

您需要先找出错误并提出解决方案。

:)

【讨论】:

  • 非常感谢...我没有提到。错误是:“您尝试上传的图像超出了最大高度或宽度。”我尝试使用较小的图像并且它有效...
【解决方案2】:
public function register() {

    $config = array(
        'upload_path' => './img/user',
        'allowed_types' => 'jpg|jpeg|JPG|JPEG|png',
        'max_size' => '200',
        'max_width' => '1024',
        'max_height' => '768');

    $this->upload->initialize($config);

    // you need to make sure that the upload path is existing
    // and also check the folder permission to be rwxr-xr-x
    // if you installed in a server where permission is required
    // for you to create image inside the folder

    // create a folder img/user in the root directory of the project
    // where application or system located

    // this will check 
    if ($this->upload->do_upload('Aks')) {
        echo 'success'; die;
    } else {
        var_dump($this->upload->display_errors());die;
    }


}

File Upload CodeIgniter

【讨论】:

  • 我无法理解你的代码中有哪些 OP 没有的正确之处??
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多