4
votes

I made a page that will upload certain file types. It works fine in my local development but not in production. It won't pass the do_upload() function. Nothing is displayed beyond that.

$path = 'uploads';
echo 'path: '. $path .' <br>'; 

//-- config for uplaod --
$configUpdload['upload_path']   = $path ;
$configUpdload['allowed_types'] = 'gif|jpg|png|xls|xlsx|pdf';
$configUpdload['max_size']   = '4000'; //size in kilobytes
$configUpdload['encrypt_name']  = TRUE;

//-- load upload library --
$this->load->library('upload');

$this->upload->initialize($configUpdload);

if ($_FILES['fileref']['name']!="")
{
    ini_set('display_errors', true);
    error_reporting(E_ALL);

    echo 'uploadAttachment<br>';

    $uploaded = $this->upload->do_upload("fileref");

    echo 'uploaded: '. $uploaded . '<br>';

    if ($uploaded == true)
    {
        echo 'uploaded data<br>';
        $inputUp = $this->upload->data();
        echo 'data: '. print_r($inputUp,true) . '<br>'; 
        $uploadInput['orig_name']   = $inputUp['orig_name'];
        $uploadInput['enc_name']    = $inputUp['file_name'];
        $uploadInput['extension']   = $inputUp['file_ext'];

        echo 'uploaded true<br>';
    }else{
        die($this->upload->display_errors());
    }
}

I tried changing the upload_path to non existing folder, it show 'The upload path does not appear to be valid'. Means the do_upload() does work right?

The uploads folder permission is 777.

I also tried using absolute path but still doesnt show anything pass do_upload().

Or anything to do with the server?

Does anyone knows what is happening? Help much appreciated.

Thanks.

[edit1]

Nothing in the server's error log nor normal log. I also set $config['log_threshold'] = 4; No error log.

[edit2]

Production server is 3rd party web hosting under linux. I tried php_info() and trace anything to do with upload.

file_uploads        On  On  
max_file_uploads    20  20  
pload_max_filesize  30M 30M  
upload_tmp_dir      /tmp/   /tmp/  
suhosin.upload.disallow_binary  0   0  
suhosin.upload.disallow_elf 1   1  
suhosin.upload.max_uploads  25  25  
suhosin.upload.remove_binary    0   0  
suhosin.upload.verification_script  no value  

   I also tried decrease the filesize $configUpdload['max_size'] = '10'; but no message after do_upload() still.

[Edit3] My folder structure:

public_html/gtapp/
public_html/gtapp/csystem/ <- is system folder
public_html/gtapp/v1/ <- is application folder
public_html/gtapp/media/
public_html/gtapp/uploads/
public_html/gtapp/license.txt

In config.php:

$config['base_url'] = 'http://www.example.com/gtapp/

In index.php:

$application_folder = 'v1';

when I do APPPATH . 'uploads'; to above code is shows:

uploadAttachment
path: v1/uploads
uploaded: 
The upload path does not appear to be valid.

I tried $path = $_SERVER['DOCUMENT_ROOT'] . '/gtapp/uploads'; It just shows:

uploadAttachment
path: /home/user/domains/example.com/public_html/gtapp/uploads 

[Edit4]

I made a crude version of native PHP upload codes and it works. I dont think it is a server issue. Below is the code:

$name = 'fileref'; 

$upload_path    = './uploads/';
$allowed_types  = array("jpg", "jpeg", "gif", "png", "xls", "xlsx", "pdf");
$extension      = end(explode(".", $_FILES[$name]["name"]));
$max_size       = '4000';

if ($_FILES['fileref']['name']!="")
{
    if ((($_FILES[$name]["type"] == "image/gif")
        || ($_FILES[$name]["type"] == "image/jpeg")
        || ($_FILES[$name]["type"] == "image/pjpeg")
        || ($_FILES[$name]["type"] == "image/png")
        || ($_FILES[$name]["type"] == "image/x-png")
        || ($_FILES[$name]["type"] == "application/excel")
        || ($_FILES[$name]["type"] == "application/vnd.ms-excel")
        || ($_FILES[$name]["type"] == "application/msexcel")
        || ($_FILES[$name]["type"] == "application/pdf")
        || ($_FILES[$name]["type"] == "application/x-download"))
        && (round($_FILES[$name]["size"]/1024,2) < $max_size )
        && in_array($extension, $allowed_types))
        {

            if ($_FILES[$name]["error"] > 0)
            {
                echo $_FILES[$name]["error"]);
            }
            else
            {
                $uploadInput['orig_name']   = $_FILES[$name]["name"];
                $uploadInput['enc_name']    = sha1($_FILES[$name]["name"]);
                $uploadInput['extension']   = $_FILES[$name]["type"];

                $moved = move_uploaded_file($_FILES[$name]["tmp_name"], $upload_path . $uploadInput['enc_name'] . '.' . $extension);

                if($moved)
                    echo 'success';
                else
                    echo 'fail';

            }
        }
}
3
Maybe there's something in the error log that can help you debug the issue. - Kemal Fadillah
What webserver are you running? It could be your php.ini or your web server configuration refusing files over a certain size. - Brendan
Thanks for the response. @KemalFadillah. Nothing in the server's error log nor normal log. I also set $config['log_threshold'] = 4; No error log. - mF4d
Thanks for the response. @Brendan. Im not sure what to look. Production server is 3rd party web hosting under linux. I tried php_info() and trace anything to do with upload. file_uploads On On max_file_uploads 20 20 pload_max_filesize 30M 30M upload_tmp_dir /tmp/ /tmp/ suhosin.upload.disallow_binary 0 0 suhosin.upload.disallow_elf 1 1 suhosin.upload.max_uploads 25 25 suhosin.upload.remove_binary 0 0 suhosin.upload.verification_script no value I also tried decrease the filesize $configUpdload['max_size'] = '10'; but no message after do_upload() still - mF4d
Run ps ax | grep httpd on the command line. You can replace httpd with nginx as well if the only result is "grep httpd". This command shows running processes that match your grep pattern. Have you tried uploading a very small file? - Brendan

3 Answers

0
votes

I had a similar problem with CI and trying to verify a files existance outside of app folder, and found that CI has this one enviromental veriable reserved for itself. APPPATH, it finds the core folder that CI is in, from the index.php level where you have your application and system folder. So if you try replacing $configUpdload['upload_path'] = './uploads' ; with $configUpdload['upload_path'] = APPPATH.'uploads';

you may run into a bit more luck.

0
votes

I had this issue once and all I did was to change the following:

Change:

$path = 'uploads';
$configUpdload['upload_path'] = $path ;

To:

$path = './uploads';
$configUpdload['upload_path'] = $path;

Or just:

$configUpdload['upload_path'] = './uploads';
0
votes

Change this line

$upload_path = './uploads/';

to

$upload_path = FCPATH.'uploads/';

And it will work for you on production server as well.