Solved

using a variable with getimagesize()

Posted on 2009-05-18
5
607 Views
Last Modified: 2013-12-12
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
Comment
Question by:gamebits
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 24417585
Show us the code, please.
0
 
LVL 28

Author Comment

by:gamebits
ID: 24417600
<?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
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 24417636
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
 
LVL 28

Author Closing Comment

by:gamebits
ID: 31582823
Thank you sir, appreciated.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 24417667
Thanks for the points - glad we could shoot this one down quickly!  Best, ~Ray
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

734 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