homepage Welcome to WebmasterWorld Guest from 54.161.246.212
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
function.imagecreatefromjpeg: failed to open stream:
imagecreatefromjpeg
howiek03

5+ Year Member



 
Msg#: 4000719 posted 2:53 am on Oct 4, 2009 (gmt 0)

i get this error Warning: imagecreatefromjpeg(testpicture.jpeg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in ..... on line 27

the interesting thing is that the image name and image size fields display the correct information. just no image in the image field. and the image javascript code works fine too...

using php 5+
gd 2+ is enabled

plz help.


<div align="center">Click on an image to view it in a separate window.</div><br />
<table align="center" cellspacing="5" cellpadding="5" border="1">
<tr>
<td align="center"><b>Image</b></td>
<td align="center"><b>Image Name</b></td>
<td align="center"><b>Image Size</b></td>
</tr>
<?php # images.php

$dir = 'uploads';

$files = scandir($dir);

foreach ($files as $image) {

if (substr($image, 0, 1) != '.') {

$image_size = getimagesize("$dir/$image");

$file_size = round ( (filesize ("$dir/$image")) / 1024) . "kb";

>>>line 27>>> $display = imagecreatefromjpeg($image); // Read all the images into an array.

echo "<tr>
<td>$display</td>
<td><a href=\"javascript: create_window('$image',$image_size[0],$image_size[1])\">$image</a></td>
<td>$file_size</td>
</tr>";

}
}
?>
</table>

 

jd01

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4000719 posted 4:17 am on Oct 4, 2009 (gmt 0)

$image_size = getimagesize("$dir/$image");

$file_size = round ( (filesize ("$dir/$image")) / 1024) . "kb";

>>>line 27>>> $display = imagecreatefromjpeg($image); // Read all the images into an array.

The first thing I'm seeing is you're requesting the information for the image size and file size and actual image from two different locations...

$image_size and $file_size come from here: $dir/$image
$display comes from here: $image (no $dir included.)

My guess is it's a path issue, and $dir/$image will probably correct it since the other's are getting you the information...

$display = imagecreatefromjpeg($dir/$image);

If not, double check on the path you are using to the actual image. I would definitely use a server relative path (/begins-with-a/slash) rather than directory relative (does-not-begin-with-a/slash) since you are using a pop-up.

howiek03

5+ Year Member



 
Msg#: 4000719 posted 7:40 am on Oct 4, 2009 (gmt 0)

hey jd,

i tried setting the path and the methods that seems to almost work are either of these two:
$display = imagecreatefromjpeg("$dir/$image");
$display = imagecreatefromjpeg("./$dir/$image");

the error goes away, but now i get a message in the image boxes:
Resource id #12
Resource id #15
Resource id #18
Resource id #21

there are four images in the uploads dir.

thank you for getting me this far. i appreciate all the help.

p1lky

10+ Year Member



 
Msg#: 4000719 posted 6:31 pm on Oct 4, 2009 (gmt 0)

to display the image in the table, you need to use html
<td><img src="\$dir/$img\"></td>

imagecreatefromjpeg() stores the picture in memory so that it can be manipulated.

howiek03

5+ Year Member



 
Msg#: 4000719 posted 9:56 pm on Oct 4, 2009 (gmt 0)

hey p1lky,

thanks for the obvious, i cant believe i didnt realize it pointer... :)
i got so lost in php land i forgot about html...

so it works with this:

<td><img src='$dir/$image' width='100px' height='70px'/></td>

images display!

thank you so very much... :)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved