steveBK
steveBK

Reputation: 17

function does not return variable

I'm trying to write an upload function that returns the location of the uploaded file. the location will be used in a function that calls the Imagick class to resize the image a few times for use in responsive design. Only problem is...I'm getting nothing from the return statement and can't figure out why. Heeeelp! *before i gouge my eyes out

HERE'S THE CODE*

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);

Upvotes: 0

Views: 54

Answers (1)

eggyal
eggyal

Reputation: 126025

You need to assign the result of calling the function (the $fileDest variable declared wtihin the function itself ceases to exist once code execution leaves the scope of the function):

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

See Variable scope and Returning values for more information.

Upvotes: 2

Related Questions