1
我想上傳一個圖像,並保存圖像完整路徑在我的圖像表,但我不知道如何得到它的完整路徑出$this->upload->data()
陣列這是我的代碼如下。圖像上傳與codeigniter
//assigns the user's sessioned id to the variable $user_id
$user_id = $this->session->userdata('user_id');
//sets rules for the image that is being uploaded
$config['overwrite'] = FALSE; //does not overwrite any image adds +1 instead
$config['encrypt_name'] = FALSE; //encrypts the images name
$config['remove_spaces'] = TRUE; //removes spaces from the images name
$config['file_name'] = $user_id."_0.jpg";/*gives the image a new name combination of the user's id and a number*/
$config['upload_path'] = './uploads'; // the uploaded images path
$config['allowed_types'] = 'jpg|png';/*types of image extentions allowed to be uploaded*/
$config['max_size'] = '2048';// maximum file size that can be uploaded (2MB)
if (! is_dir($config['upload_path'])) /* this checks to see if the file path is wrong or does not exist.*/
die("THE UPLOAD DIRECTORY DOES NOT EXIST"); // error for invalid file path
$this->load->library('upload',$config); /* this loads codeigniters file upload library*/
//this checks for errors incase the image upload breaks a set rule.
if (! $this->upload->do_upload()) {
echo "UPLOAD ERROR ! ".$this->upload->display_errors(); //image error
}
else {
// success message to show that the image was successfuly uploaded.
echo "THE IMAGE HAS BEEN UPLOADED : "; var_dump($this->upload->data());
}
這甚至沒有顯示的東西!圖像上傳,但完整的路徑沒有顯示。 –
那麼,if語句的哪個部分最終結束了? – simnom
if($ uploaded_image = $ this-> upload-> do_upload()){ //成功顯示圖片成功上傳的成功消息。 回聲「圖片已被上傳:」; –