2011-07-06 39 views
1

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

例如:

<?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 
} 

?> 

我试图使用CodeIgniter框架uploadify整合,所以我使用的控制器功能来处理上载。我不想在控制器中的函数中写入很多回显命令,我试图使用“返回1”,但它不起作用。 有什么办法来

回答

0

你不得不花些时间回声,但更组织和避免很多回声,你可以这样做:

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 
?> 

希望这有助于。欢呼声