Jump to content

How to start this?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
12 replies to this topic

#1
Whitey

Whitey

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 255 posts
Okay well i have a new upload site i been working on for a few days. Has my login/register system and my upload system. When you register it makes you, your own folder chmod to 755 and the folder has the name you registered with on it. So when you upload it uploads to your folder.

So here is an example.
Index of /whitey

That shows your uploads in your folder.
Well i am going to make a PHP script in the folder that shows all the users images.. (limits 20 per page) but the thing is how to make it show all the images in the folder.. Decending by date..

If you could help me start this that would be great..

#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
I do not believe the file has an attribute of when it was created - it does have an attribute of when the file was last accessed and last written to (PHP: fileatime - Manual and PHP: filemtime - Manual ). The first thing that jumps out at me is to use a database. Store the file name, date it was created, and any other pertinent information regarding the image in the database. With SQL you can use ORDER BY on the date created column and you are pretty much done - you can even add a LIMIT 20 to only show 20 images. The other possibility is to store a timestamp as part of the images name: untitled-1213098600.jpg. Then just sort by the timestamp.

#3
Whitey

Whitey

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 255 posts
someone gave me this code
<?php
//Open images directory
$dir = @ dir("/images/icons/");

//List files in images directory
while (($file = $dir->read()) !== false)
  {
 $imagelist[$i] = array('filename' => $file , 'lastModified ' => filemtime('images/icons/'.$file)); 
 $i++;
  }
  print_r($imagelist);

$dir->close();
?> 

But it doesn't really seem to work. And i dont really understand it

P.S The upload has nothing to do with a database ;)

Edited by Whitey, 10 June 2008 - 05:02 PM.


#4
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts

Whitey said:

P.S The upload has nothing to do with a database ;)
Perhaps it should. As mentioned in my previous post, without manually logging it, I'm pretty sure it is impossible to get the creation date of the file.

#5
Whitey

Whitey

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 255 posts
I figured a way around it with a help of a friend.. i will post what i did later.. atm i need help at something else..

okay so i do
$_SERVER['PHP_SELF'];
gets /upload_script/whitey/home.php

but i want to strip the home.php.. so it shows /upload_script/whitey/ If you guys figure out how to do this before me let me know...

EDIT:
FIgured it out.. To fast for you :)
$address_url = $_SERVER['PHP_SELF'];

		$address_url_new = str_replace("home.php", "", $address_url);

		die($address_url_new);

Edited by Jaan, 11 June 2008 - 09:13 AM.
Please use tags when you're posting your codes!


#6
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
dirname($_SERVER['PHP_SELF']);


#7
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
There seems to be an endless stream of predefined PHP functions, for everything! I wouldn't be surprised if there was a function called ShowTheUsersImagesMostRecentTwentyImages(). :)
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#8
ReekenX

ReekenX

    Programmer

  • Members
  • PipPipPipPip
  • 134 posts
Why you do not using database? It's more secure and when you decide add some functions (features) you will see that it was good idea to use database system.
www.jarmalavicius.lt | www.github.com/reekenx | www.twitter.com/reekenx

#9
Whitey

Whitey

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 255 posts
Yeah i understand that but this is the way i started it. I will be probably making a version 2 for that some other time.. But i am coding in all different aspects for learning purpose's so if i run into something like this later i will know how to do it. ;)

#10
ReekenX

ReekenX

    Programmer

  • Members
  • PipPipPipPip
  • 134 posts
ShowTheUsersImagesMostRecentTwentyImages() - short and self describing name :D
www.jarmalavicius.lt | www.github.com/reekenx | www.twitter.com/reekenx

#11
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
If he were using a database, ShowTheUsersImagesMostRecentTwentyImages() = "SELECT * FROM `images` ORDER BY `date` DESC LIMIT 20"

#12
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
I meant a predefined function called ShowTheUsersImagesMostRecentTwentyImages(), but never mind.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums