|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Greetings, all. I have a directory with images, of which I need to place the file names in a column in a MySQL db. There are two files for every image:
image.jpg and image_t.jpg (the thumbnail for image.jpg) What I would like to do is strip the file extension (as well as the '_t.jpg') from the filenames, and just enter the 'root' filename (image). This way I have only one db entry per image pair. Can anyone help me with this? Thanks!! Dale. [This message has been edited by rainmaker (edited July 03, 2000).] |
|
#2
|
|||
|
|||
|
Hi
First you get the filenames in the directory: $myDir = opendir("path/to/images/"); then you do something like: $lastImage = ""; while($entry = readdir($myDir)) { if($entry != "." && $entry != "..") { $entry = ereg_replace("_t.jpg", "", $entry); $entry = ereg_replace(".jpg", "", $entry); if($entry != $lastImage) { <store $entry in db> } $lastImage = $entry; } } NOTICE: this is not bug-checked, tested or validated in any way. It is furthermore not the most elegant way to solve the problem, but it will get the job done ![]() When you store the imagename you should also make a check, that it doesn't exist allready. Perhaps even make the name unique. Hope this will help you. Regards // Martin |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > PHP Development > retrieve filenames from directory |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|