将图像从单击的路径移动到另一个路径 link;代码点火器
Move Image to another Path from a clicked link; Codeigniter
想法是将当前用户选择的图像移动到也在数据库中的另一个路径。这是控制器:
public function makeProfile() {
if (isset($_GET['makeProfile']));
$data['user_id']= $this->session->userdata['user_id'];
$fileName = ('uploads/'.$fileName);
if($this->images_model->makeProfile($data, $fileName)) {
echo "Success";
$msg = 'File successfully moved to profile';
redirect(site_url().'main/');
}else{
echo "Failure";
模特:
Public function makeProfile ($data, $fileName) {
return $this->db->get_where('images', ['user_id' => $this->session->userdata('user_id')])->row();
move_uploaded_file('uploads/'.$fileName, 'uploads/profile/'.$fileName);
if($this->db->affected_rows() == '1') {
return TRUE;
}
return FALSE;
}
景观:
<a class="profile" href="<?= base_url('main/makeProfile') ?>">Make Profile</a>
我可能做错了,但希望这里有人可以引导我朝着正确的方向前进。在此先感谢所有输入!
模型中的函数 makeProfile
有问题。您正在获取记录,然后将其返回。下面的代码没有执行
Public function makeProfile ($data, $fileName) {
$fileName= $this->db->get_where('images', ['user_id' => $this->session->userdata('user_id')])->row()->image;
// Will copy foo/test.php to bar/test.php
// overwritting it if necessary
copy('uploads/'.$fileName, 'uploads/profile/'.$fileName));
if($this->db->affected_rows() == '1') {
return TRUE;
}
return FALSE;
}
从其手册页中引用几个相关句子:
Makes a copy of the file source to dest.
If the destination file already exists, it will be overwritten.
想法是将当前用户选择的图像移动到也在数据库中的另一个路径。这是控制器:
public function makeProfile() {
if (isset($_GET['makeProfile']));
$data['user_id']= $this->session->userdata['user_id'];
$fileName = ('uploads/'.$fileName);
if($this->images_model->makeProfile($data, $fileName)) {
echo "Success";
$msg = 'File successfully moved to profile';
redirect(site_url().'main/');
}else{
echo "Failure";
模特:
Public function makeProfile ($data, $fileName) {
return $this->db->get_where('images', ['user_id' => $this->session->userdata('user_id')])->row();
move_uploaded_file('uploads/'.$fileName, 'uploads/profile/'.$fileName);
if($this->db->affected_rows() == '1') {
return TRUE;
}
return FALSE;
}
景观:
<a class="profile" href="<?= base_url('main/makeProfile') ?>">Make Profile</a>
我可能做错了,但希望这里有人可以引导我朝着正确的方向前进。在此先感谢所有输入!
模型中的函数 makeProfile
有问题。您正在获取记录,然后将其返回。下面的代码没有执行
Public function makeProfile ($data, $fileName) {
$fileName= $this->db->get_where('images', ['user_id' => $this->session->userdata('user_id')])->row()->image;
// Will copy foo/test.php to bar/test.php
// overwritting it if necessary
copy('uploads/'.$fileName, 'uploads/profile/'.$fileName));
if($this->db->affected_rows() == '1') {
return TRUE;
}
return FALSE;
}
从其手册页中引用几个相关句子:
Makes a copy of the file source to dest.
If the destination file already exists, it will be overwritten.