PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 2nd, 2000, 12:42 PM
rainmaker rainmaker is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Posts: 23 rainmaker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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).]

Reply With Quote
  #2  
Old July 4th, 2000, 08:39 AM
kaasgaard kaasgaard is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2000
Location: Aalborg, Denmark
Posts: 36 kaasgaard User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 14
Send a message via ICQ to kaasgaard
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > retrieve filenames from directory

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap