?
Solved

using a variable with getimagesize()

Posted on 2009-05-18
5
Medium Priority
?
618 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 111

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 111

Accepted Solution

by:
Ray Paseur earned 2000 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 111

Expert Comment

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

Featured Post

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

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…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

777 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