Solved

What is causing this error?

Posted on 2013-06-08
4
301 Views
Last Modified: 2013-06-10
Head out to http://www.hihatwebdesign.com/Showdown/album_view.php?album_name=Contestants. You'll see with several pictures I'm getting an error and I don't know why.

Compare the same page to http://www.countryshowdown.com/album_view.php?album_name=Contestants and there's no error at all.

The error is getimagesize(http://www.countryshowdown.com/Photos/Ashley Headshot.jpg) [function.getimagesize]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/content/09/6568309/html/hihatwebdesign.com/Showdown/album_gallery_view.php on line 60

I've attached my code. Could someone tell me where I'm blowing it?

<?php
//here's my resizing function

//declare your variables

function sweet_imgResize($width, $height, $target) {
//takes the larger size of the width and height and applies the formula. Your function is designed to work with any image in any size.
if ($width > $height) {
$percentage = ($target / $width);
} else {
$percentage = ($target / $height);
}

//gets the new value and applies the percentage, then rounds the value

$width = round($width * $percentage);
$height = round($height * $percentage);
//returns the new sizes in html image tag format...this is so you can plug this function inside an image tag so that it will set the image to the correct size, without putting a whole script into the tag.
//echo "width=\"$width\" height=\"$height\"";
return "width=\"$width\" height=\"$height\"";

}

?>

<?php
$maxcols = 4; 
include ("carter.inc");
$cxn = mysqli_connect($host,$user,$password,$database)
or die ("couldn't connect to server");

$query = "select * from photos where album_name = '$the_album_name' order by photo_date";
$result = mysqli_query($cxn, $query)
or die ("Couldn't execute query.");

$count=0; // initialize count

while ($row=mysqli_fetch_assoc($result))
{
$count++; // increment count

if ($count == 1)
 { // initalize table
?>

	<table width="585" border="0" align="center" cellspacing="1" cellpadding="1">
	<tr>

<?php
 }
?>

	<td align="center">
	<?php
	$photo_url = str_replace("+", " ", $row['url']);
	$photo_id = $row['id'];
	?>

	<?php
	$mypicture = getimagesize("http://www.countryshowdown.com/Photos/$photo_url");
	?>
	<A HREF="album_viewer_kickoff.php?album_name=<?php echo $the_album_name; ?>&photo_id=<?php echo $photo_id; ?> "><img src="http://countryshowdown.com/thumbs/<?php echo $photo_url; ?>" <?php echo sweet_imgResize($mypicture[0],  $mypicture[1], 100); ?> 
	border="0" alt="<?php echo $row['description']; ?>">
	</a>
	</td>

<?php
if ($count % $maxcols == 0)
 { // if modulus of count is = 0 then end row
 ?>
 </tr><tr><td colspan="4">&nbsp;<BR></td><tr>
<?php 
 }

}

if ($count)
{ // data exists
 $fill = ($count % $maxcols); // current column
if ($fill){ // if not last column already fill in blank columns
for ($i = $fill; $i <= ($maxcols -1); $i++){
echo "<td>&nbsp;</td>";
}
echo "</tr>";
 }
 echo "</table>";
}
?>

Open in new window

0
Comment
Question by:brucegust
4 Comments
 
LVL 17

Assisted Solution

by:OmniUnlimited
OmniUnlimited earned 167 total points
ID: 39232447
getimagesize() requires that the url be encoded.  You have a space in the filename.  Try using url's like http://www.countryshowdown.com/Photos/Sarah%20Anderson.jpg instead of http://www.countryshowdown.com/Photos/Sarah Anderson.jpg.  Make line 55 like the following:

$photo_url = urlencode(str_replace("+", " ", $row['url']));

Open in new window

0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 167 total points
ID: 39232463
I always get rid of the spaces so I don't have that problem.
0
 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 166 total points
ID: 39235090
0
 

Author Comment

by:brucegust
ID: 39235236
Yeah, I know...

Even after implementing the OminUnlimited's suggestion, I was still running into troubles. So what I did was apply the collabrative wisdom of this thread and went back and renamed the photos that weren't showing up properly and I got it done.

Thanks, Ray and everybody else. Page looks good now!
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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 four methods for overlaying images in a container on a web page
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

786 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