2014-04-23 163 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