Hello
I have finaly managed to make my photo-uploader work. The next step is to be able to show all uploaded photo's by month. So If I would upload a photo today; it would go in the folder 'December 2009', under the 'photo' tab.
Unfortunately I don't even know how to automaticaly get uploaded photos on my webpage. Momentarily they just go in the folder 'uploads'. Do I have to make subfolders right away, so that pictures added in december '09 go in the folder uploads/december '09? And how do I do that?
And how do I show those pictures?
Probably a big question, but I'll do with a good link too if that's easier... I've googled it and looked on some forums but havnt found what i've been looking for.
[SOLVED][PHP] Showing uploaded files by date
Moderator: General Moderators
[SOLVED][PHP] Showing uploaded files by date
Last edited by arbitter on Sun Jan 03, 2010 4:41 am, edited 1 time in total.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: [PHP] Showing uploaded files by date
When an image is uploaded check to see if the current month year: date() directory exists: file_exists(). If not, create it: mkdir().
Use move_uploaded_file() to move the uploaded image to that directory.
To show the images, get a list of all of them from the directory using glob(), then loop through them: foreach() and display with the standard HTML img tag.
Use move_uploaded_file() to move the uploaded image to that directory.
To show the images, get a list of all of them from the directory using glob(), then loop through them: foreach() and display with the standard HTML img tag.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Re: [PHP] Showing uploaded files by date
Code: Select all
filemtime()Re: [PHP] Showing uploaded files by date
As for displaying images automatically after uploading; that works fine after some more searching the web after glob() and foreach(). fitted a maximum width too.
Going to try and fix the date-problem now.
Thank you for the fast answers
Going to try and fix the date-problem now.
Thank you for the fast answers
Re: [PHP] Showing uploaded files by date
Okay first a small question;
how can you give an image a maximum width? Because if I just give width='70%' also smaller images get pulled out so they are '70%'. And Id like only images that are bigger than 70% of the screen to be cropped to that 70%
So the filemtime() works, but I really don't know how to get the month and year out of it...
Something like this?
how can you give an image a maximum width? Because if I just give width='70%' also smaller images get pulled out so they are '70%'. And Id like only images that are bigger than 70% of the screen to be cropped to that 70%
So the filemtime() works, but I really don't know how to get the month and year out of it...
Something like this?
Code: Select all
If (file_exists([color=#FF0000]something with the date[/color])
{ move_uploaded_file($_FILES["file"]["tmp_name"],
"uploads/" . [color=#FF0000]"something to determine month and year"[/color] . $_FILES["file"]["name"]);}
else { mkdir([color=#FF0000]something with the date[/color]) move_uploaded_file($_FILES["file"]["tmp_name"],
"uploads/" . [color=#FF0000]"something to determine month and year"[/color] . $_FILES["file"]["name"]);}Re: [PHP] Showing uploaded files by date
I found another way to do it;
Code: Select all
<?php
$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"]);
}
}
?>