PDA

View Full Version : images/year/month/day


glloeb
06-25-2006, 04:33 PM
Hey all, I just downloaded pixelpost today, and I am quite excited as it seems like it may be what I have been looking for in terms of photoblogging software. However, my one concern was whether or not it is possible to store uploaded files in the folder

images/yearuploaded/monthuploaded/dayuploaded

I have a very limited knowledge of php (I took classes a long time ago), but I was hoping someone might have the solution.

I appreciate your help,
Gabriel Loeb

glloeb
06-25-2006, 07:14 PM
This code is found in /admin/new_image.php

Can anyone give me an idea as to whether I could achieve what I want by changing $time_stamp_r = gmdate("Y/m/d/His",time()+(3600 * $tz)). Basically, I'm wondering if php is smart enough to create the directories required when it writes a file, or would I need to add more code to do that?

// prepare the file
if($_FILES['userfile'] != "") {
$userfile = strtolower($_FILES['userfile']['name']);
$tz = $cfgrow['timezone'];
if ($cfgrow['timestamp']=='yes')
$time_stamp_r = gmdate("YmdHis",time()+(3600 * $tz)) .'_';
$uploadfile = $upload_dir .$time_stamp_r .$userfile;
if(move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
chmod($uploadfile, 0644);
$result = check_upload($_FILES['userfile']['error']);
$filnamn =strtolower($_FILES['userfile']['name']);
$filnamn = $time_stamp_r .$filnamn;

glloeb
06-25-2006, 07:15 PM
I am hoping that this change would result in the file being written to

image/year/month/day/time_title.jpg

glloeb
06-25-2006, 07:54 PM
// prepare the file
if($_FILES['userfile'] != "") {
$userfile = strtolower($_FILES['userfile']['name']);
$tz = $cfgrow['timezone'];
if ($cfgrow['timestamp']=='yes')
$Ymd = gmdate ("Y/m/d");
$time_stamp_r = $Ymd . gmdate("His",time()+(3600 * $tz)) .'_';
if (mkdir($Ymd, 0644) {
$uploadfile = $upload_dir .$time_stamp_r .$userfile;
if(move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
chmod($uploadfile, 0644); ....etc

If not, perhaps this would work? Sorry for all the posts.

Vernon.Trent
06-25-2006, 08:26 PM
ok, looks fine.
but how should PP read from all the directories?
in the admin panel you can tell PP where the images are.
in that case, if your PP "lives" 5 years or more, you'll get a lot of directories :)


in the admin panel you can specify that PP should add a date+timestamp to your original image. the filename will look like uploaddateandtime_yourimagename.jpg

what's the aim behind your idea to create all these directories?

thanks.

glloeb
06-25-2006, 09:24 PM
Well, since I believe you can already sort through and list by year or month (not sure since I'm new to the scripts) it would really just be for my ocd and MAYBE hackable links, by which I mean something along the lines of domain.com/index.php?showimage="/2006/06/25/" so that an informed user would be able to use the link to find an image from a certain day without searching. But mostly for my ocd.

Vernon.Trent
06-25-2006, 09:54 PM
for that, I think it's better to use mod rewrite method thru .htaccess

Vernon.Trent
06-25-2006, 10:00 PM
please check here for mod rewrite method

http://forum.pixelpost.org/showthread.php?t=3778

glloeb
06-25-2006, 11:17 PM
Hmm, but how would that allow me to pull the times they were created with that? I see some promising looking variables (TIME_YEAR, TIME_MON, TIME_DAY) but I presume they are set to the current time, and not whenever my files happened to be created..

glloeb
06-26-2006, 03:11 AM
My current plight, after playing around with new_image.php:

// prepare the file
if($_FILES['userfile'] != "") {
$userfile = strtolower($_FILES['userfile']['name']);
$tz = $cfgrow['timezone'];
if ($cfgrow['timestamp']=='yes') {
$Y = $_POST['post_year'];
$m = $_POST['post_month'];
$d = $_POST['post_day'];
if (!is_dir($upload_dir .$Y)) {mkdir($upload_dir .$Y, 0644); }
if (!is_dir($upload_dir .$Y ."/" .$m)) {mkdir($upload_dir .$Y ."/" .$m, 0644); }
if (!is_dir($upload_dir .$Y ."/" .$m ."/" .$d)){mkdir($upload_dir .$Y ."/" .$m ."/" .$d, 0644); }
$Ymd = $Y ."/" .$m ."/" .$d ."/";
}
$uploadfile = $upload_dir .$Ymd .$userfile;
if(move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
chmod($uploadfile, 0644);


roar:

Warning: is_dir(): Stat failed for ../images/2006/06 (errno=13 - Permission denied) in /home/glloeb/public_html/admin/new_image.php on line 184

Warning: mkdir(../images/2006/06): Permission denied in /home/glloeb/public_html/admin/new_image.php on line 184

Warning: is_dir(): Stat failed for ../images/2006/06/25 (errno=13 - Permission denied) in /home/glloeb/public_html/admin/new_image.php on line 185

Warning: mkdir(../images/2006/06/25): Permission denied in /home/glloeb/public_html/admin/new_image.php on line 185

Warning: move_uploaded_file(../images/2006/06/25/window.jpg): failed to open stream: Permission denied in /home/glloeb/public_html/admin/new_image.php on line 189

Warning: move_uploaded_file(): Unable to move '/tmp/phpIv36yc' to '../images/2006/06/25/window.jpg' in /home/glloeb/public_html/admin/new_image.php on line 189

using 1.5

glloeb
06-26-2006, 05:19 AM
Okay, after much fooling around with permissions new_image.php is functioning and is able to store images to /images/year/month/day.

However, the index page is not aware of this and it looks for the images however it does, I'm not up for more of this craziness tonight, but if anyone knows where in the index.php file it links to the image or has suggestions on how to go about fixing this please tell me. Also, if anyone is interested in the code when I get this working I would be glad to supply it.

GeoS
06-26-2006, 07:14 AM
You must also put /year/moth/day as prefix for image name which you store in DB in SQL's insert statement.

glloeb
06-26-2006, 03:46 PM
Excellent, added 5 characters of code and its working. Thanks for your help everyone.