Solved

Add text to the database image path

Posted on 2013-11-18
5
261 Views
Last Modified: 2014-03-16
I need to display images on my site that take image path values like this from the database...

uploads/album_17/55487_0f635b_a0c242.jpg

I need to change these path to..

uploads/album_17/th_155487_0f635b_a0c242.jpg

Any idea how (using PHP) I can add that 'th_1' bit to the path?
0
Comment
Question by:BrighteyesDesign
  • 3
  • 2
5 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39657907
Please see http://www.laprbass.com/RAY_temp_brighteyesdesign.php

As with any data-dependent problem the quality of the answers you get will be directly related to the quality of the test data you give us.

<?php // RAY_temp_brighteyesdesign.php
error_reporting(E_ALL);

/** SEE: http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28297539.html
 * Source: uploads/album_17/55487_0f635b_a0c242.jpg
 * Result: uploads/album_17/th_155487_0f635b_a0c242.jpg
 */

// THE DATA EXAMPLES
$source = 'uploads/album_17/55487_0f635b_a0c242.jpg';
$result = 'uploads/album_17/th_155487_0f635b_a0c242.jpg';

// TRANSFORM THE SOURCE INTO THE RESULT
$newtxt = str_replace('17/', '17/th_1', $source);

// TEST THE TRANSFORMATION
if ($newtxt == $result) echo "SUCCESS!";

Open in new window

Cheers, ~Ray
0
 

Author Comment

by:BrighteyesDesign
ID: 39667448
Thanks Ray,

Apologies but I should have explained that the album number changes too. So when the next gallery is uploaded it'll be album_18

I've attached a screenshot of the database which might make things clearer.

Is it possible (using php) to delete everything up to and including the second '/' and replacing it with something along the lines of...

uploads/album_$AlbumID/th_155487_0f635b_a0c242.jpg

Hope this makes sense!
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39667557
attached a screenshot of the database...

?

0
 

Author Comment

by:BrighteyesDesign
ID: 39668362
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39668686
Maybe something like this?  It's all about string concatenation -- the process of assembling a character string (in this case the album image path) from component parts.  Concatenation is done with the dot (period) in PHP.  See also this note:
http://us3.php.net/manual/en/ref.strings.php#51100

<?php // RAY_temp_brighteyesdesign.php
error_reporting(E_ALL);

/** SEE: http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28297539.html
 * Source: uploads/album_17/55487_0f635b_a0c242.jpg
 * Result: uploads/album_17/th_155487_0f635b_a0c242.jpg
 */

// THE DATA EXAMPLES
$albumID = '17';
$source  = 'uploads/album_XX/55487_0f635b_a0c242.jpg';
$result  = 'uploads/album_17/th_155487_0f635b_a0c242.jpg';

// TRANSFORM THE SOURCE INTO THE RESULT
$substrs = explode('/', $source);
$newtxt  = current($substrs) . DIRECTORY_SEPARATOR . "album_$albumID" . DIRECTORY_SEPARATOR . 'th_1' . end($substrs);

// TEST THE TRANSFORMATION
if ($newtxt == $result) echo "SUCCESS!";

Open in new window

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now