• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 635
  • Last Modified:

using a variable with getimagesize()

I'm trying to get image size so I can make a thumbnail on the fly, the path to the image is kept in a database and the image is in one of many folders. the path saved in the db has the html tag so basically
<img src="http://www.domain.com/folder/subfolder/subfolder/imagename.jpg">

I'm using str_replace to remove the <img src= and > from the string and I assign the result to a variable ($img)

than I'm trying to use getimagesize($img); but I get this error message

getimagesize("http://www.domain.com/folder/subfolder/subfolder/imagename.jpg") [function.getimagesize]: failed to open stream: No such file or directory

the thing is if I hardcode the path instead of using the variable it work fine.

Anybody know why and how to make it work with a variable?
0
gamebits
Asked:
gamebits
  • 3
  • 2
1 Solution
 
Ray PaseurCommented:
Show us the code, please.
0
 
gamebitsAuthor Commented:
<?php
error_reporting(E_ALL);
$originalString = '<img src="http://www.cemond.com/Trading_Cards/Topps/Zorro_1958/2f.jpg">';
$newString = str_replace("<img src=","",$originalString);
$newnewString = str_replace(">","",$newString);

$info = getimagesize("$newnewString") ;

//print_r($info);

$width = $info[0];
$height= $info[1];

  $width = $width/3;
  $height = $height/3;
 
echo "<a href=\"http://www.cemond.com/Trading_Cards/Topps/Zorro_1958/2f.jpg\"><img src=\"http://www.cemond.com/Trading_Cards/Topps/Zorro_1958/2f.jpg\" width=\"$width\" height=\"$height\" border=0></a>";

?>

originalstring will be pulled from database query
0
 
Ray PaseurCommented:
This worked for me.  Note that I had to modify the str_replace at lines 6 and 7 to take out the double quotes.

HTH, ~Ray
<?php // RAY_temp_gamebits.php
error_reporting(E_ALL);
echo "<pre>\n";
 
$originalString = '<img src="http://www.cemond.com/Trading_Cards/Topps/Zorro_1958/2f.jpg">';
$newString = str_replace('<img src="',"",$originalString);
$newnewString = str_replace('">',"",$newString);
 
$info = getimagesize($newnewString) ;
var_dump($newnewString);
var_dump($info);
 
$width = $info[0];
$height= $info[1];
 
  $width = $width/3;
  $height = $height/3;
 
echo "<a href=\"http://www.cemond.com/Trading_Cards/Topps/Zorro_1958/2f.jpg\"><img src=\"http://www.cemond.com/Trading_Cards/Topps/Zorro_1958/2f.jpg\" width=\"$width\" height=\"$height\" border=0></a>";

Open in new window

0
 
gamebitsAuthor Commented:
Thank you sir, appreciated.
0
 
Ray PaseurCommented:
Thanks for the points - glad we could shoot this one down quickly!  Best, ~Ray
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now