Jump to content

put uploaded files in folder per month


arbitter

Recommended Posts

What I want to do is that if you upload a photo in say January '10, the photo goes in the folder 'January '10'. I've managed to get get files uploaded and displayed, but only get the files in a global folder. I was told to use filemtime(), date(), file_exists() and mkdir(). I'm not so bright with the time part though. This is what I've come up with:

 

If (file_exists(something with the date))
{ move_uploaded_file($_FILES["file"]["tmp_name"],
      "uploads/" . "something to determine month and year" . $_FILES["file"]["name"]);}
else { mkdir(something with the date) move_uploaded_file($_FILES["file"]["tmp_name"],
      "uploads/" . "something to determine month and year" . $_FILES["file"]["name"]);}

 

To determine filemtime() is "filemtime($_FILES["file"]["tmp_name"])"

This is where 'm stuck, andI don't even know if this works..

Anybody any help please?

Link to comment
Share on other sites

Hi,

 

Filemtime will give you the last time the file was changed, not the time of uploading; if I understand your question well, you'd like to orden them on the time they were uploaded, correct?

 

$uploaddir = date("F")." - ".date("y");

if(is_uploaded_file($_FILES['file']['tmp_name']))
	{
		move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);
	}

 

That would move them to a dir named 'Month - year in two digit representation'.

 

Example:

 

January - 10

 

Good luck.

Link to comment
Share on other sites

I've done some work but it doesn't quite work yet.

$uploaddir = date("F")." '".date("y");
		if(is_uploaded_file($_FILES['file']['tmp_name']))
		{
			if (file_exists("/uploads/" . $uploaddir))
			{ 	move_uploaded_file($_FILES['file']['tmp_name'], "/uploads/" . $uploaddir.'/'.$_FILES['file']['name']); }
			else { mkdir("/uploads/" . $uploaddir);
				move_uploaded_file($_FILES['file']['tmp_name'], "/uploads/" . $uploaddir.'/'.$_FILES['file']['name']); }
		}

 

But something isn't quite right yet; when I ttry uploading I get warnings about the mkdir() and about move_uploaded_file()

 

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.