I am want to upload image into following folder structure:
/var/www/html/project/public/upload/userimage/2016/04/07/thumbnail/image.png
^ ^ ^
Year Month Date
and I have wrote this code:
$Day = date('d'); // Get date
$Month = date('m'); // Get month
$Year = date('Y'); // Get year
$data = $_POST['base64']; // Get base64 image data
$imageName = hash('ripemd160', time()).'.png';
if (!file_exists(public_path().'/upload/userimage/'.$Year.'/'.$Month.'/'.$Day.'/thumbnail')) {
mkdir(public_path().'/upload/userimage/'.$Year.'/'.$Month.'/'.$Day.'/thumbnail', 0777, true);
}
$url = public_path().'/upload/userimage/'.$Year.'/'.$Month.'/'.$Day.'/thumbnail/'.$imageName;
list($type, $data) = explode(';', $data);
list(, $data) = explode(',', $data);
$data = base64_decode($data);
file_put_contents($url.'/'.$imageName, $data);
and getting this error:
file_put_contents(/var/www/html/project/project/public/upload/userimage/2016/04/07/thumbnail/8b38eb25ce97d428afcd80d6ddcd16b8ca266a52.png/8b38eb25ce97d428afcd80d6ddcd16b8ca266a52.png): failed to open stream: No such file or directory
I just want to upload image to directory folder with generating folder Year -> Month -> Date if Year/Month/Date is changed.
I will appreciate if you help me to make my code more proper :)
Thanks.
mkdirfunction and then upload files into it.