Image and PDF upload problem (Your server does not support the GD function required to process this)

edited June 2011 in Bug Reports
Hi,

I'm trying to implement img and pdf upload form fields (with img resize feature as illustrated in tutorial)
But after hitting save image_lib gives me an error (Your server does not support the GD function required to process this type of image.)
I have GD lib installed on my server.
Here is my catalog module code:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
require_once(FUEL_PATH.'models/base_module_model.php');

class Catalog_model extends Base_module_model {


public $filters = array('model_number');
public $required = array('model_number');



function __construct()
{
parent::__construct('catalog'); // table name
}

function list_items($limit = null, $offset = null, $col = 'model_number', $order = 'model_number, asc')
{
$this->db->select('id, model_number, use_, type_, grade_, published', FALSE);
$data = parent::list_items($limit, $offset, $col, $order);
return $data;
}

function form_fields($values = array())
{
$fields = parent::form_fields($values);


// to limit the image folder to just the projects folder for selection
$fields['image']['class'] = 'asset_select images/products';
//$fields['description']['class'] = 'wysiwyg';

// put all project images into a projects subfolder
$fields['image_upload']['upload_path'] = assets_server_path('products', 'images');

$fields['image_upload']['overwrite'] = TRUE;

// fix the preview by adding projects in front of the image path since we are saving it in a subfolder
if (!empty($values['image']))
{
$fields['image_upload']['before_html'] = '
image
';
}



$fields['pdf']['label'] = 'Select PDF';
$fields['pdf']['class'] = 'asset_select pdf/products';

$fields['pdf_upload']['label'] = '..OR Upload PDF';
$fields['pdf_upload']['upload_path'] = assets_server_path('products', 'pdf');
$fields['pdf_upload']['type'] = 'file';
$fields['pdf_upload']['accept'] = 'pdf';
$fields['pdf_upload']['overwrite'] = TRUE;


return $fields;


}

function on_after_post($values)
{
$CI =& get_instance();
$CI->load->library('image_lib');



// create the thumbnail if an image is uploaded
if (!empty($CI->upload))
{
$data = $CI->upload->data();
if (!empty($data['full_path']))
{
$thumb_img = assets_server_path('products/'.$this->thumb_name($data['file_name']), 'images');

// resize to proper dimensions
$config = array();
$config['source_image'] = $data['full_path'];
$config['create_thumb'] = FALSE;
//$config['new_image'] = $thumb_img;
$config['width'] = 240;
$config['height'] = 340;
$config['master_dim'] = 'auto';
$config['maintain_ratio'] = TRUE;
$CI->image_lib->clear();
$CI->image_lib->initialize($config);
if (!$CI->image_lib->resize())
{
$this->add_error($CI->image_lib->display_errors());
}

}
}

return $values;
}

// delete the images as well
function on_before_delete($where)
{
$id = $this->_determine_key_field_value($where);
$data = $this->find_by_key($id);
$files[] = assets_server_path('products/'.$data->image, 'images');
$files[] = assets_server_path('products/'.$this->thumb_name($data->image), 'images');
foreach($files as $file)
{
if (file_exists($file))
{
@unlink($file);
}
}
}

function thumb_name($image)
{
return preg_replace('#(.+)(\.jpg|\.png)#U', '$1_thumb$2', $image);
}




}


class Product_model extends Base_module_record {

function get_url()
{

return site_url('catalog/item/'.$this->id);
}

function get_image_path()
{
return img_path('products/'.$this->image);
}

}



?>


I also specified :

$config['editable_asset_filetypes'] = array(
'images' => 'jpg|jpeg|jpe|gif|png',
'pdf' => 'pdf',
'media' => 'jpg|jpeg|jpe|png|gif|mov|mp3|aiff'
);

in My_fuel.php, but still now luck.

Comments

  • edited 9:24AM
    A few questions:
    1. When you say no luck, do you mean that that file is not being saved to the folder or is the image not being resized correctly?
    2. Does $data['full_path'] have the correct path to to where you want the image to upload and is that folder writable?
    3. Are you able to see the files in the $_FILES array in the on_after_post method?
  • edited 9:24AM
    Image file resized and saved perfectly but not the pdf.
    After saving the post I can see image in image folder but pdf is not there.

    2. i have check full_puth there all correct and writable.
  • edited 9:24AM
    The assets/pdf/products is writable correct?
  • edited 9:24AM
    yes it's correct
    i have tried to modify if statement for resize to cache only images
    is it right?

    if (!empty($CI->upload))
    {
    $data = $CI->upload->data();
    if ((!empty($data['full_path'])) && ($data['is_image'] == 1))
    {
    $thumb_img = assets_server_path('products/'.$this->thumb_name($data['file_name']), 'images');

    // resize to proper dimensions
    $config = array();
    $config['source_image'] = $data['full_path'];
    $config['create_thumb'] = FALSE;
    //$config['new_image'] = $thumb_img;
    $config['width'] = 240;
    $config['height'] = 340;
    $config['master_dim'] = 'auto';
    $config['maintain_ratio'] = TRUE;
    $CI->image_lib->clear();
    $CI->image_lib->initialize($config);
    if (!$CI->image_lib->resize())
    {
    $this->add_error($CI->image_lib->display_errors());
    }

    }
    }
  • edited 9:24AM
    What is the file size of the PDF document? If it is over 1000KB then it won't upload unless you've changed the FUEL config. You can change the max upload file size for FUEL in MY_config using the 'assets_upload_max_size' parameter. Or sometimes your server may be configured to not upload files over a certain size. However, to change the server configuration, you may need to use .htaccess. Could that be the issue?
Sign In or Register to comment.