Php 无法使用图像上载插入数据
当运行成功时,但当插入数据和上载图像包含错误时,我将插入数据并将图像上载到数据库中 图像的路径不正确 您的服务器不支持处理此类映像所需的GD功能 如果插入数据而不上载图像不是错误,该如何处理?图像数据库进入默认图像 这是我的控制器Php 无法使用图像上载插入数据,php,codeigniter,codeigniter-3,Php,Codeigniter,Codeigniter 3,当运行成功时,但当插入数据和上载图像包含错误时,我将插入数据并将图像上载到数据库中 图像的路径不正确 您的服务器不支持处理此类映像所需的GD功能 如果插入数据而不上载图像不是错误,该如何处理?图像数据库进入默认图像 这是我的控制器 public function save(){ $this->load->library('image_lib'); //$nama_asli = $_FILES['userfile']['name']; $id = $thi
public function save(){
$this->load->library('image_lib');
//$nama_asli = $_FILES['userfile']['name'];
$id = $this->input->post('id',TRUE);
$config['file_name'] = $id ;//'_'.'_'.$nama_asli;
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
$config['max_size'] = '100000';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('userfile'))
{
$files = $this->upload->data();
$fileNameResize = $config['upload_path'].$config['file_name'];
$size = array(
array('name' => 'thumb','width' => 100, 'height' => 100, 'quality' => '100%')
);
$resize = array();
foreach($size as $r){
$resize = array(
"width" => $r['width'],
"height" => $r['height'],
"quality" => $r['quality'],
"source_image" => $fileNameResize,
"new_image" => $url.$r['name'].'/'.$config['file_name']
);
$this->image_lib->initialize($resize);
if(!$this->image_lib->resize())
die($this->image_lib->display_errors());
}
}
else
{
$data = array('upload_data' => $this->upload->data());
$get_name = $this->upload->data();
$nama_foto = $get_name['file_name'];
$this->mcrud->savealat($nama_foto);
redirect('instrument/detailalat');
}
}
这是我的模型
function savealat($nama_foto) {
$data = array(
'id' => $this->input->post('id'),
'namaalat' => $this->input->post('namaalat'),
'dayalistrik' => $this->input->post('dayalistrik'),
'merk' => $this->input->post('merk'),
'namasupplier' => $this->input->post('namasupplier'),
'nokatalog' => $this->input->post('nokatalog'),
'noseri' => $this->input->post('noseri'),
'category' => $this->input->post('category'),
'lokasi' => $this->input->post('lokasi'),
'pengguna' => $this->input->post('pengguna'),
'status' => $this->input->post('status'),
'jadwalkal' => $this->input->post('jadwalkal'),
'manual' => $this->input->post('manual'),
'dateinput' => $this->input->post('date'),
'foto' => $nama_foto
//'created' => $tanggal
);
$this->db->insert('tbdetail', $data);
}
如果我是对的,问题是你把上传放在了其他地方。试着移动代码并告诉我它是否有效也许这个答案可以帮助你。评论部分并没有更多的建议可以帮助你们找到解决办法 但是,图像是否保存在您的主目录中?@LorenzoMagno,如果我插入数据并上传存储在目录中的照片,我之前给出了一个简短的代码,请尝试。循环将是提交表单,然后图像将被移动到目录中,然后插入到数据库中。如果这还不清楚,请标记meNo prob乐意帮助outsorry@Lorenzo Magno,现在如果我插入数据并上传照片,会发生错误,会显示什么错误?我仍然会在这里帮助解决与我的问题相同的错误,包括
消息:未定义变量:url行号:174
和此脚本行174“new_image”=>$url.$r['name'./'.$config['file_name']
Oyes!我现在明白你的错误了。您从未在任何地方定义过$url。你在想什么网址?
public function save(){
$this->load->library('image_lib');
//$nama_asli = $_FILES['userfile']['name'];
$id = $this->input->post('id',TRUE);
$config['file_name'] = $id ;//'_'.'_'.$nama_asli;
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
$config['max_size'] = '100000';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('userfile'))
{
$files = $this->upload->data();
$fileNameResize = $config['upload_path'].$config['file_name'];
$size = array(
array('name' => 'thumb','width' => 100, 'height' => 100, 'quality' => '100%')
);
$resize = array();
foreach($size as $r){
$resize = array(
"width" => $r['width'],
"height" => $r['height'],
"quality" => $r['quality'],
"source_image" => $fileNameResize,
"new_image" => base_url().$r['name'].'/'.$config['file_name']
);
$this->image_lib->initialize($resize);
if(!$this->image_lib->resize())
die($this->image_lib->display_errors());
}
$data = array('upload_data' => $this->upload->data());
$get_name = $this->upload->data();
$nama_foto = $get_name['file_name'];
$this->mcrud->savealat($nama_foto);
redirect('instrument/detailalat');
}
else
{
//Moved your code up there
}
}