Solved

Add text to the database image path

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

863 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

17 Experts available now in Live!

Get 1:1 Help Now