Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在没有活动记录codeigniter的情况下,将非法字符串偏移上载并存储图像到mysql_Php_Mysql_Codeigniter - Fatal编程技术网

Php 在没有活动记录codeigniter的情况下,将非法字符串偏移上载并存储图像到mysql

Php 在没有活动记录codeigniter的情况下,将非法字符串偏移上载并存储图像到mysql,php,mysql,codeigniter,Php,Mysql,Codeigniter,我在没有active record codeigniter的情况下将图像上传并存储到mysql时出错 它显示 消息:非法字符串偏移量“file\u ext” 不仅是文件外部,还有文件大小。此问题仅在我不使用以下代码的活动记录时发生: <?php if ($_FILES['userfile']['error'] <> 4) { $nmfile = $this->input->post('name'); $config['upload_path']

我在没有active record codeigniter的情况下将图像上传并存储到mysql时出错

它显示

消息:非法字符串偏移量“file\u ext”

不仅是文件外部,还有文件大小。此问题仅在我不使用以下代码的活动记录时发生:

<?php
if ($_FILES['userfile']['error'] <> 4)
{
  $nmfile = $this->input->post('name');

  $config['upload_path']      = './assets/images/user/';
  $config['allowed_types']    = 'jpg|jpeg|png|gif';
  $config['max_size']         = '2048'; // 2 MB
  $config['max_width']        = '2000'; //pixels
  $config['max_height']       = '2000'; //pixels
  $config['file_name']        = $nmfile; 

  $this->load->library('upload', $config);

  if (!$this->upload->do_upload())
  {
    $this->create();
  }
    else
    {
      $userfile = $this->upload->data();
      $thumbnail                = $config['file_name'];

      $config['image_library']  = 'gd2';

      $config['source_image']   = './assets/images/user/'.$userfile['file_name'].'';
      // membuat thumbnail
      $config['create_thumb']   = TRUE;
      // rasio resolusi
      $config['maintain_ratio'] = FALSE;
      // lebar
      $config['width']          = 150;
      // tinggi
      $config['height']         = 150;

      $this->load->library('image_lib', $config);
      $this->image_lib->resize();

      $id               = $this->input->post('id');
      $name             = $this->input->post('name');
      $username     = $this->input->post('username');
      $psw1             = $this->input->post('psw1');
      $psw2             = $this->input->post('psw2');
      $usertype     = $this->input->post('usertype');
      $userfile     = $nmfile;
      $userfile_type    = $userfile['file_ext'];
      $userfile_size    = $userfile['file_size'];

      $sql = $this->db->query("INSERT INTO user (id, name, username, psw1, psw2, usertype, userfile, userfile_type, userfile_size)
                          VALUES ('$id', '$name', '$username', password('$psw1'), password('$psw2'), '$usertype', '$userfile', '$userfile_type', '$userfile_size') ");

      $this->session->set_flashdata('message', '<div class="alert alert-success alert">Data berhasil dibuat</div>');
  redirect(site_url('auth/user'));
    }
}
?>


任何帮助都将不胜感激,谢谢你

我相信你能以如下可爱的方式取得成果:

if (!empty($_FILES)) {

  $data = array(
      'id' => $this->input->post('id'),
      'name' => $this->input->post('name'),
      'username' => $this->input->post('username'),
      'psw1' => $this->input->post('psw1'),
      'psw2' => $this->input->post('psw2'),
      'usertype' => $this->input->post('usertype')
  );
  $upload = $this->imageUpload();
  if (!$upload) {
    $this->create();
  } else {
    $data['userfile'] = $upload['upload_data']['file_name'];
    $data['userfile_type'] = $upload['upload_data']['file_ext'];
    $data['userfile_size'] = $upload['upload_data']['file_size'];

    $this->db->insert('user', $data);
    $this->session->set_flashdata('message', '<div class="alert alert-success alert">Data berhasil dibuat</div>');
    redirect(site_url('auth/user'));
  }
}

$this->input->post('name')的值是多少
function imageUpload() {
  $config = array(
      'upload_path' => "uploads",
      'allowed_types' => "*",
      'overwrite' => true,
     'max_size' => "5048000", // Can be set to particular file size , here it is 2 MB(2048 Kb)
     'max_height' => "3000",
     'max_width' => "3000"
  );
  $this->upload->initialize($config);
  $this->load->library('upload', $config);

  if ($this->upload->do_upload('userfile')) {
    $response = array('upload_data' => $this->upload->data());
    $this->doResize($response['upload_data']['file_name']);

    return $response;
  } else {
    $error = array('error' => $this->upload->display_errors());
    return false;
    // var_dump($error); die(); // check errors
  }
}

function doResize($filename) {

  $sourcePath = './assets/images/user/' . $filename;
  $targetPath = './assets/images/user/thumb_' . $filename;

  $config_manip = array(
     'image_library' => 'gd2',
     'source_image' => $sourcePath,
     'new_image' => $targetPath,
     'maintain_ratio' => true,
     'width' => 100,
     'height' => 100
  );
  $this->image_lib->initialize($config_manip);
  $this->load->library('image_lib', $config_manip);

 if (!$this->image_lib->resize()) {
   // Check errors
   echo $this->image_lib->display_errors();
   die();
 }
}