Codeigniter do_upload在生产服务器中没有响应

时间:2012-09-09 06:55:39

标签: php codeigniter file-upload

我制作了一个会上传某些文件类型的页面。 它在我的本地开发中工作正常,但在生产中没有。 它不会传递do_upload()函数。除此之外没有任何东西显示出来。

$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());
    }
}

我尝试将upload_path更改为非现有文件夹,显示“上传路径似乎无效”。是否do_upload()可以正常工作?

上传文件夹权限为777。

我也尝试使用绝对路径,但仍然没有显示任何传递do_upload()。

或者与服务器有什么关系?

有谁知道发生了什么?非常感谢。

感谢。

[EDIT1]

服务器的错误日志和普通日志中没有任何内容。我还设置$ config ['log_threshold'] = 4;没有错误日志。

[EDIT2]

生产服务器是linux下的第三方Web托管。我尝试了php_info()并跟踪与上传有关的任何事情。

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  

我也试过减少filesize $ configUpdload ['max_size'] ='10';但是在do_upload()之后仍然没有消息。

[EDIT3] 我的文件夹结构:

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

在config.php中:

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

在index.php中:

$application_folder = 'v1';

当我对上面的代码APPPATH . 'uploads';显示时:

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

我试过$path = $_SERVER['DOCUMENT_ROOT'] . '/gtapp/uploads'; 它只是显示:

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

[Edit4]

我制作了原生PHP上传代码的粗略版本,但它确实有效。我不认为这是一个服务器问题。以下是代码:

$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 个答案:

答案 0 :(得分:0)

我遇到了与CI类似的问题并尝试验证app文件夹之外的文件存在,并发现CI具有为其自身保留的这一个环境。 APPPATH,它从index.php级别找到CI所在的核心文件夹,其中包含应用程序和系统文件夹。因此,如果您尝试将$configUpdload['upload_path'] = './uploads' ;替换为$configUpdload['upload_path'] = APPPATH.'uploads';

你可能会遇到更多的运气。

答案 1 :(得分:0)

我曾经遇到过这个问题而我所做的就是更改以下内容:

变化:

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

要:

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

或者只是:

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

答案 2 :(得分:0)

更改此行

$upload_path = './uploads/';

$upload_path = FCPATH.'uploads/';

它也将在生产服务器上为您工作。