我有一个完整的PHP脚本,我从codecanyon购买并且作者不支持costum工作......它是用Codeigniter框架制作的,它的工作正常且完美,但脚本不支持
我搜索谷歌并找不到答案。
我尝试过创建>上传 - 控制器>上传视图>上传 模型,仅上传到特定网址中的指定文件夹,例如site.com/uploadimage。
我想问一下是否有任何方法可以将此功能集成到系统中...是一个php新手。 许多人提前感谢...
答案 0 :(得分:0)
我希望这可以帮到你。
创建此文件夹路径以上传图片: app_data / images / account /
// Your Controller
Class User extends CI_Controller
{
// This upload method
function upload_user_photo()
{
$path = 'app_data/images/account/';
if(!file_exists($path))
{
mkdir($path, 0777, true);
}
$file_name = increment_string('image_profile', '-'); //use codeigniter string helper
$config['upload_path'] = $path;
$config['file_name'] = $file_name;
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
//Take an action if photo has been uploaded
if($this->upload->do_upload('image'))
{
$upload_data = $this->upload->data();
// View response from upload data
echo "<pre>";
print_r ($upload_data);
echo "</pre>";
// Array key is column name of your table
$data =
[
'user_id' => 'insert our user id',
'photo' => $upload_data['file_name']
];
//Take action save to your model
$this->load->model('your_model_name');
$this->your_model_name->save_profile_image($data);
}
}
}
#Model
Class Your_model_name extends CI_Model
{
function save_profile_image($data)
{
$this->db->insert($data);
}
}