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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.