Solved

using a variable with getimagesize()

Posted on 2009-05-18
5
590 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
  • 3
  • 2
5 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
Show us the code, please.
0
 
LVL 28

Author Comment

by:gamebits
Comment Utility
<?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 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
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
Comment Utility
Thank you sir, appreciated.
0
 
LVL 108

Expert Comment

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

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
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 …

762 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

9 Experts available now in Live!

Get 1:1 Help Now