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
https://forums.phpfreaks.com/topic/210788-help-with-upload-pics-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.