Uploadify with CodeIgniter
In the uploadify, the backend PHP file echos "1" to indicate that the upload is complete. Similarly if I'd want to get some error information from the PHP script to the upload page, i would need to echo the error in the function.
For example:
<?php
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FIL开发者_如何转开发ES['Filedata']['name'];
move_uploaded_file($tempFile,$targetFile);
}
if ($error){ //some error.
echo $error; //dont want to echo
} else {
echo '1'; //dont want to echo
}
?>
I'm trying to integrate the uploadify with CodeIgniter framework, therefore I'm using the controller function to process the upload. I would not like to write many echo commands in my function in the controller, I tried to used "return 1" but it does not work. Is there any way to
You have to echo sometime, but to be more organize and avoid many echos you could do:
function processError($error){
if ($error){
return $error;
} else {
return '1';
}
}
And then, in your controller
<?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
?>
Hope this helps. Cheers
精彩评论