astubblefield
asked on
Modifying Image Name in PHP
I have the DEVELOPER TOOL BOX for DREAMWEAVER CS3 in PHP.
Using the Create Thumbnail it creates a thumbnail with the name of FILENAME_wxh.jpg, or myimage_80x80.jpg, the name of the image is stored in a database as myimage.jpg.
I am creatiing a XML file and i need to be able to take the database image name of myimage.jpg and modify the string to myimage_80x80.jpg.
So what i need is to find out how in PHP that i can modify the name myimage.jpg to myimage_80x80.jpg, by some how inserting the _80x80 between the name and the extension.
I was told that it would be something like, <img src="(<?php echo $row_Recordset1['Image']; ?>)_80x80, true)" />
Using the Create Thumbnail it creates a thumbnail with the name of FILENAME_wxh.jpg, or myimage_80x80.jpg, the name of the image is stored in a database as myimage.jpg.
I am creatiing a XML file and i need to be able to take the database image name of myimage.jpg and modify the string to myimage_80x80.jpg.
So what i need is to find out how in PHP that i can modify the name myimage.jpg to myimage_80x80.jpg, by some how inserting the _80x80 between the name and the extension.
I was told that it would be something like, <img src="(<?php echo $row_Recordset1['Image']; ?>)_80x80, true)" />
I couldn't test the above code, so there are 2 mistakes i see, replace all $row vars to $row_Recordset1.
and also you can change the number 4 for this strlen(strrchr($row_Record set1['Imag e'], '.'))
hope it helps
and also you can change the number 4 for this strlen(strrchr($row_Record
hope it helps
ASKER
I'm not quite sure, but here is what I came up with form you post, when I view it at http://realestate.stunis.com/test.php and right click the properties I get, " http://realestate.stunis.com/uploads/thumbnails/_80x80 "
Here is the code of the page:
<?php require_once('Connections/ dbRealesta te.php'); ?>
<?php
if (!function_exists("GetSQLV alueString ")) {
function GetSQLValueString($theValu e, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_rea l_escape_s tring") ? mysql_real_escape_string($ theValue) : mysql_escape_string($theVa lue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_ dbRealesta te, $dbRealestate);
$query_Recordset1 = "SELECT id_propGen, (Image) AS PHOTO FROM propGeneral WHERE id_propGen = 16388";
$Recordset1 = mysql_query($query_Records et1, $dbRealestate) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Records et1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1 );
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p><?php echo '<img src="uploads/thumbnails/' . substr($row['Image'], 0, (strlen($row_Recordset1['P HOTO']) - 4)) . '_80x80' . strrchr($row_Recordset1['I mage'], '.') . '" />'; ?> (Thumbnail)</p>
<p><?php echo $row_Recordset1['PHOTO']; ?> (File Name)</p>
<p>
<img src="uploads/<?php echo $row_Recordset1['PHOTO']; ?>" /> (Full Size Image)</p>
</body>
</html>
<?php
mysql_free_result($Records et1);
?>
Thanks
Here is the code of the page:
<?php require_once('Connections/
<?php
if (!function_exists("GetSQLV
function GetSQLValueString($theValu
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_rea
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_
$query_Recordset1 = "SELECT id_propGen, (Image) AS PHOTO FROM propGeneral WHERE id_propGen = 16388";
$Recordset1 = mysql_query($query_Records
$row_Recordset1 = mysql_fetch_assoc($Records
$totalRows_Recordset1 = mysql_num_rows($Recordset1
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p><?php echo '<img src="uploads/thumbnails/' . substr($row['Image'], 0, (strlen($row_Recordset1['P
<p><?php echo $row_Recordset1['PHOTO']; ?> (File Name)</p>
<p>
<img src="uploads/<?php echo $row_Recordset1['PHOTO']; ?>" /> (Full Size Image)</p>
</body>
</html>
<?php
mysql_free_result($Records
?>
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
That above example should work and is shorter.
ASKER
I tried these 4 with out luck,
<?php echo str_replace(".jpg","_80x80 .jpg",$row ['PHOTO']) ; ?>
<?php echo str_replace(".jpg","_80x80 .jpg","$ro w['PHOTO'] "); ?>
<?php echo str_replace(".jpg","_80x80 .jpg",$row _Recordset 1['PHOTO'] ); ?>
<?php echo str_replace(".jpg","_80x80 .jpg","$ro w_Recordse t1['PHOTO' ]"); ?>
I looked up the str_replace and it looks to me as if one of those should work, but something is just off a little and I can't find it.
Thanks,
<?php echo str_replace(".jpg","_80x80
<?php echo str_replace(".jpg","_80x80
<?php echo str_replace(".jpg","_80x80
<?php echo str_replace(".jpg","_80x80
I looked up the str_replace and it looks to me as if one of those should work, but something is just off a little and I can't find it.
Thanks,
ASKER
If I try <?php echo str_replace(".jpg","_80x80 .jpg","tes timage.jpg "); ?> , I get testimage_80x80.jpg, it is when I add the $row_Recordset1['PHOTO'], <?php echo str_replace(".jpg","_80x80 .jpg","$ro w_Recordse t1['PHOTO' ]"); ?> that it breaks.
What is an example of the value in $row['PHOTO']?
Try:
echo $row['PHOTO'];
See what you get. Does it end in ".jpg"? There might be a problem there.
By the way, inside a quoted string, you would remove the single-quote from around the array key.
echo "$row_Recordset1[PHOTO]"; //is correct
echo "$row_Recordset1['PHOTO']" ; //is incorrect
echo $row_Recordset1['PHOTO']; //is correct
echo $row_Recordset1[PHOTO]; //is possibly valid, but is insecure and should not be used
Try:
echo $row['PHOTO'];
See what you get. Does it end in ".jpg"? There might be a problem there.
By the way, inside a quoted string, you would remove the single-quote from around the array key.
echo "$row_Recordset1[PHOTO]"; //is correct
echo "$row_Recordset1['PHOTO']"
echo $row_Recordset1['PHOTO']; //is correct
echo $row_Recordset1[PHOTO]; //is possibly valid, but is insecure and should not be used
ASKER
JI don't know why but it started working with <?php echo str_replace(".jpg","_80x80 .jpg",$row _Recordset 1['PHOTO'] ); ?>
an example:
<?php
$link = mysql_connect('localhost',
if ($link)
{
if (@mysql_select_db('dbname'
{
$sql = 'SELECT * FROM images_table';
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)
{
echo '<img src="' . substr($row['Image'], 0, (strlen($row_Recordset1['i
}
}
else
{
echo 'no database found';
}
}
else
{
echo 'not connected';
}
?>