Jump to content

[SOLVED] clever directory creation on image upload?


delphi123

Recommended Posts

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?!

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
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.