我需要在上傳後重命名圖像名稱,因爲我的要求是我需要爲它添加id,因此可能會在數據庫中存儲圖像名稱之後。在codeigniter中上傳後重命名圖像名稱
我做的代碼與和無水印到不同的文件夾上傳圖片,但現在我想改變它的名字一樣:。
$ imageName = $ imgId「」。randomstring「」 $ EXT;
我已經嘗試使用下面的代碼,但同時存儲在兩個水印文件夾中的圖像。我想將原始圖像存儲在original_image文件夾中,並將水印圖像存儲在watermark_folder中。請幫我解決這個問題。
$getImgs = $this->photographer_model->get_uploaded_image($result);
$getExt = substr($getImgs[0]['img_name'], strrpos($getImgs[0]['img_name'],'.')+0);
$randomStr = $this->generate_random_string(20);
$fileName = $result."-".$randomStr."".$getExt;
$originalImgPath = base_url()."assets/original_image/".$fileName;
$watermarkImgPath = base_url()."assets/watermark_image/".$fileName;
$uploadOrgImg = 'assets/original_image/'.$fileName;
$uploadWaterImg = 'assets/watermark_image/'.$fileName;
$updateImg = $this->photographer_model->update_img_path($result, $fileName, $originalImgPath, $watermarkImgPath);
if(file_exists('assets/original_image/'.$getImgs[0]['img_name']) || file_exists('assets/watermark_image/'.$getImgs[0]['img_name'])) {
unlink('assets/original_image/'.$getImgs[0]['img_name']);
unlink('assets/watermark_image/'.$getImgs[0]['img_name']);
$config1['upload_path'] = 'assets/original_image/';
$config1['allowed_types'] = 'jpeg|png|jpg|svg';
$config1['file_name'] = $fileName; // set the name here
$this->load->library('upload', $config1);
$this->upload->initialize($config1);
$this->upload->do_upload('image');
$config['upload_path'] = 'assets/watermark_image/';
$config['allowed_types'] = 'jpeg|png|jpg|svg';
$config['file_name'] = $fileName; // set the name here
$this->load->library('upload', $config);
$this->upload->initialize($config);
$this->upload->do_upload('image');
}
請參考此鏈接[https://stackoverflow.com/questions/35710385/ image-missing-and-required-wordpress-amp-structure-doesnt-add-image-attribute]我希望這會有幫助 –
'''$ config ['encrypt_name']'''使用它在上傳時自動重命名文件。 – kishor10d