![]() |
PHP and external files
Is there a way to make php scan a directory...for example a folder full of pictures, and then list them in some way as links or whatever you need? If show could you show an example?
I'm building a photogallery, and it will have several different categories of pictures and I would like to use php to automate adding pictures and new brands. Heres what I want it to look like : http://sharpenedconception.com/dcdes...otogallery.jpg What do you think? |
For that job, it would be better to use a database.
Either way, here is how to list the files in a directory http://www.php.net/function.opendir |
Well I followed that link that you gave me and I did this code:
<html> <head> </head> <body> <?php $path = dirname($_SERVER['SCRIPT_FILENAME']); ?> <h3>Files in <?php print $path; ?></h3> </body> </html> And when it processed the script, all it did was output the directory name, it didnt output any files? |
Nevermind, I am stupid. I'm doing that tutorial now. Although I dont understand it all. Could you explain how using a db would be better? The reason for me wanting to do this is so that all I would have to do in the future to add pictures is drag the file into the directory. Would it still be possible using a db?
|
Anyone that could explain using a database in this situation would be greatly appreciated. I want to know all angles of the task before I approach it
|
You can use a function called
glob(). It uses a pattern to search for the required files. If all you have in that directory are images, you can use the following:http://php.net/glob php Code:
Database would be overkill for a simple thing like this which can be achieved using one function unless you want to output more information regarding the file like titles, short description, tags and much more.. |
I would like to get titles for the directory its in, and I would like them to be catagorized. You can kind of see what I mean in the link above in the preview of it.
|
Quote:
|
Ok I got it working, but it shows like 6 extra empty thumbnails when I only have three pictures in the directory? Weird...I can't wait until I am good enough at programing just to be able to know whats what and come up with my own scripts heh.
|
Quote:
|
Ah I got it, in after the * if you limit the type of files for it to pick up it wont show the extra files :)
I dont think this method will work though, I think a database will be the best idea. But I'm not sure having a database will make easy for updating it with a new picture. Any ideas? |
Quote:
You can use INSERT query on the form submission to add an image to the database then you can use SELECT query to output the images as required. ;-)It would just need one table. Table - images
|
Hm, I have only messed with a db once and it wasn't pretty. Hopefully this will turn out better lol.
|
Quote:
^^ Since, you've registered at TalkPHP where we love to help, you can just ask if any problem arises. :-) |
Ok cool thanks :-D
What do you think of this tutorial? http://www.php-mysql-tutorial.com/image-gallery/ I think with that and with this websites help I should be able to pull it off :). |
Quote:
|
Well, we will see how it goes lol, thanks for the help
|
| All times are GMT. The time now is 08:12 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0