arbitter Posted January 1, 2010 Share Posted January 1, 2010 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? Quote Link to comment Share on other sites More sharing options...
freeloader Posted January 1, 2010 Share Posted January 1, 2010 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. Quote Link to comment Share on other sites More sharing options...
arbitter Posted January 1, 2010 Author Share Posted January 1, 2010 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() Quote Link to comment Share on other sites More sharing options...
arbitter Posted January 1, 2010 Author Share Posted January 1, 2010 Nevermind, found the problem; I wrote /uploads/ instead of uploads/ :') Quote Link to comment Share on other sites More sharing options...
freeloader Posted January 1, 2010 Share Posted January 1, 2010 Glad it worked out Have fun. Quote Link to comment 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.