Solved

Add text to the database image path

Posted on 2013-11-18
5
271 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 110

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 110

Expert Comment

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

?

0
 

Author Comment

by:BrighteyesDesign
ID: 39668362
0
 
LVL 110

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating and Managing Databases with phpMyAdmin in cPanel.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

680 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