Jump to content

help with upload pics php


hamed86

Recommended Posts

hi,  I have problems when people upload pictures to my page, some images are only half, see example. http://photoagahi.com/advert/detail/------92733  this is how the code looks like:

 

if ( ! function_exists('upload'))
{
function upload($post_field, $folder = DEFAULT_ADVERT_IMAGE_FOLDER)
{
	$config['upload_path'] = $folder;
	$config['allowed_types'] = 'gif|jpg|png';
	$config['max_size'] = '5000';
	$config['encrypt_name'] = true;
	$config['remove_spaces'] = true;

	$CI =& get_instance();
	$CI->load->library('upload');
	$CI->load->library('image_lib');
	$CI->load->library('image_lib', null, 'secondary_image_lib');

	$CI->upload->initialize($config);

	if(!$CI->upload->do_upload($post_field))
		return $CI->upload->display_errors();

	$data = $CI->upload->data();






	$thumb['source_image'] = DEFAULT_ADVERT_IMAGE_FOLDER.$data['file_name'];
	$thumb['width'] = 80;
	$thumb['height'] = 60;
	$thumb['create_thumb'] = true;
	$thumb['maintain_ratio'] = true;

	$CI->image_lib->initialize($thumb);

	$thumb_result = true;
	if(!$CI->image_lib->resize())
		$thumb_result = $CI->image_lib->display_errors();


	$img_data = getimagesize(DEFAULT_ADVERT_IMAGE_FOLDER.$data['file_name']);
	if($img_data[0] > 620 || $img_data[1] > 480)
	{
		$orig['source_image'] = DEFAULT_ADVERT_IMAGE_FOLDER.$data['file_name'];
		$orig['maintain_ratio'] = true;
		$orig['width'] = 620;
		$orig['height'] = 480;

		$CI->secondary_image_lib->initialize($orig);

		$orig_result = true;
		if(!$CI->secondary_image_lib->resize())
			$orig_result = $CI->secondary_image_lib->display_errors();


		if($orig_result !== true)
			return $orig_result;

		$new_size = getimagesize(DEFAULT_ADVERT_IMAGE_FOLDER.$data['file_name']);
		if($new_size)
		{
			$data['image_width'] = $new_size[0];
			$data['image_height'] = $new_size[1];
		}
	}


	if($thumb_result === true)
	{
		$data['file_thumb_data'] = file_get_contents(DEFAULT_ADVERT_IMAGE_FOLDER.$data['raw_name'].'_thumb'.$data['file_ext']);
		$data['file_data'] = file_get_contents($data['full_path']);			
		return $data;
	}
	else 
		return $thumb_result;		
}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.