I have two functions and I am stumped on how to pass a variable between them. Here is what I have so far.
function copy_photo ($image_url, $image_description){
$rand_string = rand(0001, 9999);//create simple random string
$image_type = substr(strrchr($image_url,'.'),1);//get image type
$local_directory = "./images/";//folder to put photo
$local_image_name = $local_directory . $image_description . "-" . $rand_string . $image_type;//full directory and new image name to place photo
copy($image_url, $local_image_name);// I want the function to first copy the image here
return $local_image_name;// <---this is the variable I want to pass on
}
function store_data ($local_image_name){
//simple PDO statement to insert newly created local image url into database
}
copy_photo ($image_url, $image_description);//copy photos to folder
store_data ($image_description);//store $image_description in database
What I would like to happen is for the copy_photo function to first copy the photo and then return $local_image_name and pass it to the store_data function for storage in a database. I keep getting an error that $image_description is null when store_data tries to store it into the database. How can I successfully pass $local_image_name from one function to the next?
Thanks!!