我试图在同一个表格中插入图像,保存所有其他数据。我无法上传图像并检查其验证。这就是MODEL的代码。请给我一个解决方案吗?
<?php
class Dhani_model extends CI_Model {
function dhani_model()
{
// Call the Model constructor
//parent::Model();
}
$targetpath='\images';
$date=date("Y-m-d-H-i-s");
$targetpath=$targetpath .$date. basename($_FILES['images']['name']);
move_uploaded_file($_FILES['images']['tmp_name'], $targetpath);
public function insertData($postdata)
{
$r=$postdata['name'];
$s=$postdata['phone'];
$p=$postdata['address'];
$a=$postdata['days'];
$b=$postdata['email'];
$c=$postdata['password'];
$images=$postdata['$targetpath'];
$data = array(
'name' => $r ,
'phone'=> $s ,
'address' => $p ,
'days' => $a,
'email' => $b ,
'password'=> $c ,
'$targetpath'=> $images,
);
$query=$this->db->insert('registration', $data);
if($query)
return $query;
}
}
?>
答案 0 :(得分:0)
我认为,它可以通过声明你的$ targetpath变量并在函数内部跟随移动操作来解决。请尝试一下。
答案 1 :(得分:0)
<?php
class Dhani_model extends CI_Model {
public function __construct()
{
parent::__construct();
}
public function do_upload()
{
$targetpath='\images';
$date=date("Y-m-d-H-i-s");
$targetpath=$targetpath .$date. basename($_FILES['images']['name']);
move_uploaded_file($_FILES['images']['tmp_name'], $targetpath);
}
或
<?php
class Dhani_model extends CI_Model {
private $targetpath='\images';
private $date=date("Y-m-d-H-i-s");
public function __construct()
{
parent::__construct();
}
public function do_upload()
{
$targetpath=$this->targetpath .$this->date. basename($_FILES['images']['name']);
move_uploaded_file($_FILES['images']['tmp_name'], $this->targetpath);
}