⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Image CRUD problem (Upload-Edit-Remove)



Hamed
  • profile picture
  • Member

Posted 04 January 2013 - 08:07 AM

I am trying to use image crud for my script and all od the time I get upload Failed.
This is my code:

public function gallery() {
$this->load->library('image_CRUD');
$crud = new image_CRUD();
$crud->set_primary_key_field('pid');
$crud->set_url_field('url');
$crud->set_table('shahid_pics');
$crud->set_relation_field('shid');
$crud->set_ordering_field('order');
$crud->set_title_field('title');
$crud->set_image_path('assets/uploads/shahid');
$output = $crud->render();
$this->load->view('admin/shahid/gallery',$output);
}

folder assets/uploads/shahid exit and I am sure it is 777 also examples work fine in my server.

tlc033
  • profile picture
  • Member

Posted 04 January 2013 - 11:00 AM

Can you show print_screen image ?

Hamed
  • profile picture
  • Member

Posted 04 January 2013 - 13:30 PM

Fixed,
image_CRUD doesn't work while you work on sub folder controller like admin and else then you need to change _get_delete_url and getState

protected function _get_delete_url($value)
{
$rsegments_array = $this->ci->uri->rsegment_array();
$segments_array = $this->ci->uri->segment_array();
$rsegments_array[1] = $segments_array[1].'/'.$segments_array[2];
return site_url($rsegments_array[1].'/'.$rsegments_array[2].'/delete_file/'.$value);
}


protected function getState()
{
$rsegments_array = $this->ci->uri->rsegment_array();
$segments_array = $this->ci->uri->segment_array();
$rsegments_array[1] = $segments_array[1].'/'.$segments_array[2];
if(isset($rsegments_array[3]) && is_numeric($rsegments_array[3]))
{
$upload_url = site_url($rsegments_array[1].'/'.$rsegments_array[2].'/upload_file/'.$rsegments_array[3]);
$ajax_list_url = site_url($rsegments_array[1].'/'.$rsegments_array[2].'/'.$rsegments_array[3].'/ajax_list');
$ordering_url = site_url($rsegments_array[1].'/'.$rsegments_array[2].'/ordering');
$insert_title_url = site_url($rsegments_array[1].'/'.$rsegments_array[2].'/insert_title');
$state = array( 'name' => 'list', 'upload_url' => $upload_url, 'relation_value' => $rsegments_array[3]);
$state['ajax'] = isset($rsegments_array[4]) && $rsegments_array[4] == 'ajax_list' ? true : false;
$state['ajax_list_url'] = $ajax_list_url;
$state['ordering_url'] = $ordering_url;
$state['insert_title_url'] = $insert_title_url;

return (object)$state;
}
elseif( (empty($rsegments_array[3]) && empty($this->relation_field)) || (!empty($rsegments_array[3]) && $rsegments_array[3] == 'ajax_list'))
{
$upload_url = site_url($rsegments_array[1].'/'.$rsegments_array[2].'/upload_file');
$ajax_list_url = site_url($rsegments_array[1].'/'.$rsegments_array[2].'/ajax_list');
$ordering_url = site_url($rsegments_array[1].'/'.$rsegments_array[2].'/ordering');
$insert_title_url = site_url($rsegments_array[1].'/'.$rsegments_array[2].'/insert_title');
$state = array( 'name' => 'list', 'upload_url' => $upload_url);
$state['ajax'] = isset($rsegments_array[3]) && $rsegments_array[3] == 'ajax_list' ? true : false;
$state['ajax_list_url'] = $ajax_list_url;
$state['ordering_url'] = $ordering_url;
$state['insert_title_url'] = $insert_title_url;
return (object)$state;
}
elseif(isset($rsegments_array[3]) && $rsegments_array[3] == 'upload_file')
{
#region Just rename my file
$new_file_name = '';
//$old_file_name = $this->_to_greeklish($_GET['qqfile']);
$old_file_name = $this->_convert_foreign_characters($_GET['qqfile']);
$max = strlen($old_file_name);
for($i=0; $i< $max;$i++)
{
$numMatches = preg_match('/^[A-Za-z0-9.-_]+$/', $old_file_name[$i], $matches);
if($numMatches >0)
{
$new_file_name .= strtolower($old_file_name[$i]);
}
else
{
$new_file_name .= '-';
}
}
$file_name = substr( substr( uniqid(), 9,13).'-'.$new_file_name , 0, 100) ;
#endregion
$results = array( 'name' => 'upload_file', 'file_name' => $file_name);
if(isset($rsegments_array[4]) && is_numeric($rsegments_array[4]))
{
$results['relation_value'] = $rsegments_array[4];
}
return (object)$results;
}
elseif(isset($rsegments_array[3]) && isset($rsegments_array[4]) && $rsegments_array[3] == 'delete_file' && is_numeric($rsegments_array[4]))
{
$state = array( 'name' => 'delete_file', 'id' => $rsegments_array[4]);
return (object)$state;
}
elseif(isset($rsegments_array[3]) && $rsegments_array[3] == 'ordering')
{
$state = array( 'name' => 'ordering');
return (object)$state;
}
elseif(isset($rsegments_array[3]) && $rsegments_array[3] == 'insert_title')
{
$state = array( 'name' => 'insert_title');
return (object)$state;
}
}

I hope they fix this problem.

RSPeres
  • profile picture
  • Member

Posted 18 March 2013 - 12:39 PM

Hi Hamed,

 

I tried your fix but I'm still getting null object in render. Do you know how to use image_crud in HMVC with Codeigniter?

best regards, 


amipax
  • profile picture
  • Member

Posted 03 May 2013 - 19:39 PM

Fixed,
image_CRUD doesn't work while you work on sub folder controller like admin and else then you need to change _get_delete_url and getState

    protected function _get_delete_url($value)
    {
	 $rsegments_array = $this->ci->uri->rsegment_array();
	    $segments_array = $this->ci->uri->segment_array();
	    $rsegments_array[1] = $segments_array[1].'/'.$segments_array[2];
	 return site_url($rsegments_array[1].'/'.$rsegments_array[2].'/delete_file/'.$value);
    }
protected function getState()
{
  $rsegments_array = $this->ci->uri->rsegment_array();
	    $segments_array = $this->ci->uri->segment_array();
	    $rsegments_array[1] = $segments_array[1].'/'.$segments_array[2];
  if(isset($rsegments_array[3]) && is_numeric($rsegments_array[3]))
  {
   $upload_url = site_url($rsegments_array[1].'/'.$rsegments_array[2].'/upload_file/'.$rsegments_array[3]);
   $ajax_list_url  = site_url($rsegments_array[1].'/'.$rsegments_array[2].'/'.$rsegments_array[3].'/ajax_list');
   $ordering_url  = site_url($rsegments_array[1].'/'.$rsegments_array[2].'/ordering');
   $insert_title_url  = site_url($rsegments_array[1].'/'.$rsegments_array[2].'/insert_title');
   $state = array( 'name' => 'list', 'upload_url' => $upload_url, 'relation_value' => $rsegments_array[3]);
   $state['ajax'] = isset($rsegments_array[4]) && $rsegments_array[4] == 'ajax_list'  ? true : false;
   $state['ajax_list_url'] = $ajax_list_url;
   $state['ordering_url'] = $ordering_url;
   $state['insert_title_url'] = $insert_title_url;

   return (object)$state;
  }
  elseif( (empty($rsegments_array[3]) && empty($this->relation_field)) || (!empty($rsegments_array[3]) &&  $rsegments_array[3] == 'ajax_list'))
  {
   $upload_url = site_url($rsegments_array[1].'/'.$rsegments_array[2].'/upload_file');
   $ajax_list_url  = site_url($rsegments_array[1].'/'.$rsegments_array[2].'/ajax_list');
   $ordering_url  = site_url($rsegments_array[1].'/'.$rsegments_array[2].'/ordering');
   $insert_title_url  = site_url($rsegments_array[1].'/'.$rsegments_array[2].'/insert_title');
   $state = array( 'name' => 'list', 'upload_url' => $upload_url);
   $state['ajax'] = isset($rsegments_array[3]) && $rsegments_array[3] == 'ajax_list'  ? true : false;
   $state['ajax_list_url'] = $ajax_list_url;
   $state['ordering_url'] = $ordering_url;
   $state['insert_title_url'] = $insert_title_url;
   return (object)$state;
  }
  elseif(isset($rsegments_array[3]) && $rsegments_array[3] == 'upload_file')
  {
   #region Just rename my file
    $new_file_name = '';
    //$old_file_name = $this->_to_greeklish($_GET['qqfile']);
    $old_file_name = $this->_convert_foreign_characters($_GET['qqfile']);
    $max = strlen($old_file_name);
    for($i=0; $i< $max;$i++)
    {
	 $numMatches = preg_match('/^[A-Za-z0-9.-_]+$/', $old_file_name[$i], $matches);
	 if($numMatches >0)
	 {
	  $new_file_name .= strtolower($old_file_name[$i]);
	 }
	 else
	 {
	  $new_file_name .= '-';
	 }
    }
    $file_name = substr( substr( uniqid(), 9,13).'-'.$new_file_name , 0, 100) ;
   #endregion
   $results = array( 'name' => 'upload_file', 'file_name' => $file_name);
   if(isset($rsegments_array[4]) && is_numeric($rsegments_array[4]))
   {
    $results['relation_value'] = $rsegments_array[4];
   }
   return (object)$results;
  }
  elseif(isset($rsegments_array[3]) && isset($rsegments_array[4]) && $rsegments_array[3] == 'delete_file' && is_numeric($rsegments_array[4]))
  {
   $state = array( 'name' => 'delete_file', 'id' => $rsegments_array[4]);
   return (object)$state;
  }
  elseif(isset($rsegments_array[3]) && $rsegments_array[3] == 'ordering')
  {
   $state = array( 'name' => 'ordering');
   return (object)$state;
  }
  elseif(isset($rsegments_array[3]) && $rsegments_array[3] == 'insert_title')
  {
   $state = array( 'name' => 'insert_title');
   return (object)$state;
  }
}
I hope they fix this problem.

 

Hello ,

   

   THanks Hamed, I was lucky to have found your post, I had the same problem , I use a subfolder called Admin for my controllers, and every upload failed, i noticed in firebug console that the admin segment was missing from the url. So I changed what is mentioned here and that fixed the problem .