I'm trying to save an image inside a folder. To get this folder I need to pass three directories: Images, id from the user, id from the gallery and the generated name for the image.
$directory = "../images/" . $id . "/" . $row[0] . "/" . $new_url;
I would like to pass the directory variable to the fopen, I tried this way but is not working.
$file = fopen($directory, 'wb');
Full code:
function uploadimg_func($base, $id){
$binary=base64_decode($base);
header('Content-Type: bitmap; charset=utf-8');
$selectgallery = db_queries("SELECT id FROM `galleries` WHERE name = 'Fotos de perfil' AND user_id = '".$id."' ");
$row = mysqli_fetch_array($selectgallery);
$new_url = rand(0, pow(10, 5)) . '_' . time() . '.' . "jpg";
$directory = "../images/" . $id . "/" . $row[0] . "/" . $new_url;
$file = fopen($directory, 'wb');
fwrite($file, $binary);
fclose($file);
$createphoto = db_queries("INSERT INTO photos (`name`, `title`, `description`, `gallery_id`,`created_at`)
VALUES ('".$new_url."', '', '', '".$row[0]."', now())");
}
Thanks.