2012-04-05 13 views
6

मैं छवियों को अपलोड करने और उनका आकार बदलने का प्रयास कर रहा हूं, अब तक अपलोड काम कर रहा है और अंगूठे की नाखून छवियों का निर्माण भी कर रहा है। लेकिन मैं मूल छवि का आकार बदल नहीं सकता। जो भी हो रहा है वह यह है कि फ़ाइल सीधे मूल आकार में फ़ोल्डर में अपलोड की जाती है। मुझे लगता है कि मैं इस छवि का आकार बदलने की कोशिश कर रहा हूं, फिर मूल रूप से अपलोड की गई फ़ाइल को ओवरराइट करें।कोडइग्निटर छवि अपलोड करें और फिर इसे आकार दें

//Initialise the upload file class 
    $config['upload_path'] = './image_uploads/'; 
    $config['allowed_types'] = 'jpg|jpeg|gif|png'; 
    $config['max_size'] = '6048'; 
    $this->load->library('upload', $config); 

    $userfile = "_upload_image"; 
      //check if a file is being uploaded 
      if(strlen($_FILES["_upload_image"]["name"])>0){ 

       if (!$this->upload->do_upload($userfile))//Check if upload is unsuccessful 
       { 
        $upload_errors = $this->upload->display_errors('', ''); 
        $this->session->set_flashdata('errors', 'Error: '.$upload_errors); 
        redirect('admin/view_food/'.$food->course_id); 
       } 
       else 
       { 
        //$image_data = $this->upload->data(); 

        ////[ THUMB IMAGE ] 
        $config2['image_library'] = 'gd2'; 
        $config2['source_image'] = $this->upload->upload_path.$this->upload->file_name; 
        $config2['new_image'] = './image_uploads/thumbs'; 
        $config2['maintain_ratio'] = TRUE; 
        $config2['create_thumb'] = TRUE; 
        $config2['thumb_marker'] = '_thumb'; 
        $config2['width'] = 75; 
        $config2['height'] = 50; 
        $this->load->library('image_lib',$config2); 

        if (!$this->image_lib->resize()){ 
       $this->session->set_flashdata('errors', $this->image_lib->display_errors('', '')); 
       } 

        //[ MAIN IMAGE ] 
        $config['image_library'] = 'gd2'; 
        $config['source_image'] = $this->upload->upload_path.$this->upload->file_name; 
        //$config['new_image'] = './image_uploads/'; 
        $config['maintain_ratio'] = TRUE; 
        $config['width'] = 250; 
        $config['height'] = 250; 
        $this->load->library('image_lib',$config); 

        if (!$this->image_lib->resize()){ 
       $this->session->set_flashdata('errors', $this->image_lib->display_errors('', '')); 
       } 
       }  
      } 

उत्तर

4

आप config विकल्प

$config['overwrite'] = TRUE; 

इस में जोड़ने के लिए चाल करना चाहिए की कोशिश की थी:

यहाँ क्या कर रहा हूँ मुझे याद आ मेरी कोड है।

प्रलेखन

हैं, तो सही पर सेट किया है, तो एक आप अपलोड मौजूद हैं के रूप में एक ही नाम के साथ एक फ़ाइल, यह ओवरराइट किया जाएगा के अनुसार। यदि गलत पर सेट किया गया है, तो एक नंबर फ़ाइल नाम में जोड़ा जाएगा यदि कोई दूसरा नाम समान है।

3

मैं पिछले 20 घंटे के लिए थंबनेल बनाने के लिए कोशिश कर रहे हैं और जब तक मैं महसूस किया जहां मैं कोड के साथ खिलवाड़ किया गया था, मैं अपने config सरणी आरंभ किया जा रहा नहीं कर रहा था मैं सफल नहीं रहा था !!!

बस अपने image_lib

$this->image_lib->initialize($config); 

आशा इस के लिए आप ........... ऊपर अंगूठे काम करता है लोड करने के बाद कोड की इस पंक्ति को जोड़ने!

0

यदि आप छवि के साथ छवि के साथ खेलना पसंद करते हैं, तो मैं अत्यधिक अनुशंसा करता हूं, image_moo लाइब्रेरी।

संबंधित मुद्दे