Welcome Guest, Not a member yet? Register   Sign In
Unable to save file xxxx to final destination
#1

[eluser]Camd[/eluser]
We recently moved our website from a hosted service to our internal servers. We have a process where the content managers can upload a file. Unfortunately, this functionality no longer works and everyone receives a message “Unable to save file xxxx.jpg to file destination”.

We are using Cent OS 5.4 with PHP 5.2.10 and CodeIgniter 1.7.2.

I’ve traced the problem to the following code. To try and get past this error, I’ve set the directories to rwx for owner,group,public (the owner is also set to apache:apach). It still makes no difference. I’m at a lost at this point why it won’t work. I’m not too familar with CodeIgniter and am still in the process of learning it.

function add_uploaded_file($file_index, $field_name)
{
if (!isset($_FILES[$file_index][‘tmp_name’]))
{
$this->errors[‘upload’][] = “No file in index ‘$file_index’”;
return FALSE;
}

if (($field_info = $this->_get_file_field_details($field_name)) === FALSE)
{
$this->errors[‘upload’][] = “Unknown field name ‘$field_name’”;
return FALSE;
}

$upload_config = array(
‘upload_path’=> WEBROOT . ‘tmp’,
‘allowed_types’=>$field_info[‘allowed_types’]
);

$CI =& get_instance();
$CI->load->library(‘upload’);
$CI->upload->initialize($upload_config);

$file_path = $error = ‘’;
if ($CI->upload->do_upload($file_index))
{
$file_info = $CI->upload->data();

if ($this->_add_file_real($file_info, $field_name))
return TRUE;

if (empty($this->errors))
$this->errors[$field_name][] = “Unable to save file $file_info[orig_name] to final destination”;

if (file_exists($file_info[‘full_path’]))
unlink($file_info[‘full_path’]);
}
else
$this->errors[$field_name][] = “CI Uploader: ” . $CI->upload->display_errors(’‘, ’ ‘);

return FALSE;
}
#2

[eluser]danmontgomery[/eluser]
$this->_add_file_real() is returning false, and $this->errors is empty, so the error is being thrown... I would guess if it's not a permissions issue it's a path issue.
#3

[eluser]Camd[/eluser]
The weird thing is that the file is in the destination directory. It first gets uploaded to the temporary directory and is then moved to the destination directory. I just don't get why it is returning false.

Any other ideas on what to check?
#4

[eluser]danmontgomery[/eluser]
You should look into why $this->errors is empty... It looks like when it was written this function was expecting something in $this->errors on a successful upload. Look at the _add_file_real() function to find when that variable should be populated, then you can figure out why it's not.

Nothing else I can tell you without seeing the function.
#5

[eluser]Camd[/eluser]
I've tried putting some debug info in there. The log file shows the following:

DEBUG - 2010-03-17 10:18:25 --> Config file loaded: config/datamapper.php
DEBUG - 2010-03-17 10:18:25 --> Upload class already loaded. Second attempt ignored.
ERROR - 2010-03-17 10:18:25 --> Home_slideshow
ERROR - 2010-03-17 10:18:25 --> here 1
DEBUG - 2010-03-17 10:18:25 --> Image Lib Class Initialized
DEBUG - 2010-03-17 10:18:25 --> Language file loaded: language/english/imglib_lang.php
ERROR - 2010-03-17 10:18:25 --> Your server does not support the GD function required to process this type of image.
ERROR - 2010-03-17 10:18:25 --> JPG images are not supported.
ERROR - 2010-03-17 10:18:25 --> here 2
DEBUG - 2010-03-17 10:18:25 --> Language file loaded: language/english/number_lang.php

Here is the source code:


protected function _add_file_real($file_info, $field_name, $file_op='rename')
{
$this->clear();
log_message('error',$this->gallery);
$this->image_type = ($file_info['image_type'] == 'jpeg') ? 'jpg' : $file_info['image_type'];
if (!$this->save($this->gallery))
return FALSE;
log_message('error','here 1');

if (parent::_add_file_real($file_info, $field_name, $file_op) === FALSE)
{
log_message('error','here 2');
$this->delete();
return FALSE;
}
log_message('error','here 3');

$this->width = $this->_add_image_result['width'];
$this->height = $this->_add_image_result['height'];

if ($this->save() === FALSE)
{
log_message('error','here 4');
$this->delete();
return FALSE;
}

log_message('error','here 5');
return TRUE;
}


It looks like it is complaining about "Your server does not support the GD function required to process this type of image."

I'm pretty sure I installed the GD stuff correctly. What would be missing to not be able to process a JPG imnage file?
#6

[eluser]Camd[/eluser]
Okay, I'm an idiot. I didn't have php gd installed.

I did the following and all works fine now:

yum instal php-gd
apachectl restart

Now it works. Thank you for pointing me in the right direction.




Theme © iAndrew 2016 - Forum software by © MyBB