2
我想在我的codeigniter 3上傳圖像,並且想要向用戶顯示上傳的圖像(這是註冊級別,用戶正在輸入他的個人資料數據) I應該向他展示上傳的圖片。 我已閱讀本:安全上傳並在codeigniter中顯示圖像或文件3
移動它的public_html的外面是一個好主意,也儘量 重命名文件,只是擴展名添加到它。
和另:
不移動上傳文件目錄是從URL訪問
,但我不知道我怎麼可以顯示圖片這是不目錄可從URL訪問! 。 我沒有任何想法,這真的非常重要,我我用笨上傳類的安全性,我不知道什麼樣的安全的其他動作我應該做 這是我的控制器:
public function do_resize($img_name ,$image_original_width , $image_original_height )
{
// $nesbat = $image_original_height/$image_original_width ;
$config_manip = array(
'image_library' => 'gd2',
'source_image' => '../uploads/'.$img_name,
'new_image' => '../uploads/'.$img_name,
'maintain_ratio' => TRUE,
'create_thumb' => TRUE,
'thumb_marker' => '_thumb',
'width' => 150,
'height' => 150
);
$this->load->library('image_lib', $config_manip);
if (!$this->image_lib->resize()) {
// echo $this->image_lib->display_errors();
return false ;
}
else
{
return true ;
}
// clear //
$this->image_lib->clear();
}
function do_upload()
{
$file_name = $this->input->post("file_name") ;
$config['upload_path'] = '../uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '10000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['file_name'] = $file_name;
// delete if .gif image exists before
if (is_file('./uploads/'.$file_name.".gif") )
{
unlink("./uploads/".$file_name.".gif");
unlink("./uploads/".$file_name."_thumb.gif");
}
// delete if .gif image exists before
if (is_file('./uploads/'.$file_name.".jpg") )
{
unlink("./uploads/".$file_name.".jpg");
unlink("./uploads/".$file_name."_thumb.jpg");
}
// delete if .gif image exists before
if (is_file('./uploads/'.$file_name.".png") )
{
unlink("./uploads/".$file_name.".png");
unlink("./uploads/".$file_name."_thumb.png");
}
$this->load->library('upload', $config);
if (! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
echo "<div id='upload_status'>fail</div>";
echo "<div id='error_mesage'>".$this->upload->display_errors()."</div>";
}
else
{
$data = array('upload_data' => $this->upload->data());
$upload_data = $this->upload->data();
$uploaded_file_name = $upload_data['file_name'];
$resize = $this->do_resize($uploaded_file_name , $upload_data['image_width'] , $upload_data['image_height']) ;
if ($resize == true)
{
echo "<div id='upload_status'>success</div>";
echo "<div id='uploaded_image_link' >".$upload_data['file_name']."</div> ";
$thumb_link = str_replace($file_name,$file_name."_thumb",$upload_data['file_name']);
echo "<div id='uploaded_image_thumb_link' >".$thumb_link."</div> ";
}
//if $resize == true , nabashe -> uploade koli fail eleam mishe ta dobare anjam beshe
else
{
echo "<div id='upload_status'>fail</div>";
}
}
}