2014-04-23 167 views
0

我想写一个上传函数,返回上传文件的位置。该位置将被用于调用Imagick类的函数中,以重新调整图像几次以用于响应式设计。唯一的问题是......我没有从return语句中得到任何答案,也找不到原因。 Heeeelp! *在我剜了我的眼睛函数不返回变量

HERE'S *

function imageResize($image){ 
    //call to imagick class and resize functions will go here 

    echo 'the image to be resized is : '.$image; 

} 

function file_upload(){ 

    if(!empty($_FILES)){ 

    $tmpFldr=$_FILES['upFile']['tmp_name']; 
    $fileDest='users/uploads/'.$_FILES['upFile']['name']; 

    if(move_uploaded_file($tmpFldr,$fileDest)){ 

     echo 'Congratulations, your folder was uploaded successfully'; 

     } 
    else{ 
    echo 'Your file failed to upload<br><br>'; 

    } 
    return $fileDest; 
    } else{die('Nothing to upload');} 




} /*End file upload function */ 




file_upload(); 

imageResize($fileDest); 
+0

在'if'语句中返回通常不是一个好主意,你最好使用一个变量来存储你想返回的结果,并在函数结尾处返回该变量。 – lascort

回答

2

您需要分配调用函数的结果(声明wtihin函数本身的$fileDest变量的代码就停止一旦执行代码的叶子存在的功能的范围内):

$fileDest = file_upload(); 
imageResize($fileDest); 

更多信息请参见Variable scopeReturning values

+0

你先生..是代码人员和绅士。非常感谢。 – steveBK