0

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);
1
  • It's usually not a good idea to return inside an if statement, you're better off using a variable to store the result you want to return and return that var at the end of the function. Commented Apr 23, 2014 at 16:53

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.