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? Link to comment https://forums.phpfreaks.com/topic/186849-put-uploaded-files-in-folder-per-month/ 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. Link to comment https://forums.phpfreaks.com/topic/186849-put-uploaded-files-in-folder-per-month/#findComment-986748 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() Link to comment https://forums.phpfreaks.com/topic/186849-put-uploaded-files-in-folder-per-month/#findComment-986886 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/ :') Link to comment https://forums.phpfreaks.com/topic/186849-put-uploaded-files-in-folder-per-month/#findComment-986892 Share on other sites More sharing options...
freeloader Posted January 1, 2010 Share Posted January 1, 2010 Glad it worked out Have fun. Link to comment https://forums.phpfreaks.com/topic/186849-put-uploaded-files-in-folder-per-month/#findComment-986898 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.