Link to home
Start Free TrialLog in
Avatar of BrighteyesDesign
BrighteyesDesignFlag for Afghanistan

asked on

Add text to the database image path

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?
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

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
Avatar of BrighteyesDesign

ASKER

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!
attached a screenshot of the database...

?

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial