delphi123 Posted December 28, 2007 Share Posted December 28, 2007 Hi folks, I'm using the script available here for an image upload routine, however I'm needing to do something a bit cleverer. I'm creating an image upload script that'll save images on the server, however I need it to intelligently upload the images to directories based on the year/month. So if I upload an image today, it'll need to go into the image directory and look for a directory called 2007. if it finds it, then open it, if not create it It'll then look for a directory called dec and again open it or create it. It'll then save the file. Is this possible in php - not sure if you can create directories or not?! Quote Link to comment https://forums.phpfreaks.com/topic/83496-solved-clever-directory-creation-on-image-upload/ Share on other sites More sharing options...
GingerRobot Posted December 28, 2007 Share Posted December 28, 2007 Yeah, PHP can handle that with the mkdir and the is_dir functions: <?php $y = date('Y'); $m = date('M'); $path_to_images = 'images/'; if(!is_dir($path_to_images.$y)){ mkdir($path_to_images.$y); } if(!is_dir($path_to_images.$y.'/'.$m)){ mkdir($path_to_images.$y.'/'.$m); } $upload_to = $path_to_images.$y.'/'.$m.'/';//this is the folder that you need to upload to ?> Quote Link to comment https://forums.phpfreaks.com/topic/83496-solved-clever-directory-creation-on-image-upload/#findComment-424793 Share on other sites More sharing options...
delphi123 Posted December 28, 2007 Author Share Posted December 28, 2007 you're a frickin genius! Works beautifully! Quote Link to comment https://forums.phpfreaks.com/topic/83496-solved-clever-directory-creation-on-image-upload/#findComment-424813 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.