Php 使用CodeIgniter上传

Php 使用CodeIgniter上传,php,jquery,codeigniter,uploadify,Php,Jquery,Codeigniter,Uploadify,在uploadify中,后端PHP文件回显“1”,表示上载已完成。类似地,如果我想从PHP脚本获取一些错误信息到上传页面,我需要在函数中回显错误 例如: <?php if (!empty($_FILES)) { $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/'; $targetFile = str

在uploadify中,后端PHP文件回显“1”,表示上载已完成。类似地,如果我想从PHP脚本获取一些错误信息到上传页面,我需要在函数中回显错误

例如:

<?php

if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/';
    $targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
    move_uploaded_file($tempFile,$targetFile);
}

if ($error){        //some error.
    echo $error;  //dont want to echo
} else {
    echo '1';    //dont want to echo
}

?>

我试图将uploadify与CodeIgniter框架集成,因此我使用控制器函数来处理上传。我不想在控制器中的函数中编写很多echo命令,我尝试使用“return1”,但它不起作用。
有没有办法

有时候你必须回音,但为了更有条理,避免很多回音,你可以这样做:

function processError($error){
    if ($error){        
        return $error;  
    } else {
        return '1';    
    }
}
然后,在你的控制器里

<?php

if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/';
    $targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
    move_uploaded_file($tempFile,$targetFile);
}

echo processError($error); //Only 1 echo
?>

希望这有帮助。干杯