Hello, Its my first day coding so please forgive me for some of the silly errors I might make.
I am writing a small upload script and I want to have some sort of orginazation by uploading images to a direcotry based on the day. The following is my code but it will fail to save the file
Warning: file_put_contents(images/14-09-26/5425905a18bba.png): failed to open stream: No such file or directory
This is becuase the directory with the data part is not created how should I go about first checking that this directory is there and then creating it ?
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$today = date('y-m-j');
define('UPLOAD_DIR', 'images/' .$today. '/');
$img = $_POST['data'];
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = UPLOAD_DIR . uniqid() . '.png';
$success = file_put_contents($file, $data);
print $success ? $file : 'Unable to save the file.';
?>