By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,053 Members | 1,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,053 IT Pros & Developers. It's quick & easy.

failed to open stream error in php

P: 4
My php program to resize an jpeg image is as follows,

?php
// File and new size

$filename = '\bala\testPHP\Lavanya\Kids2.jpeg';
//$filename = 'Kids2.jpeg';
$percent = 0.5;

// Content type
//header('Content-type: image/jpeg');

// Get new sizes
list($width, $height) = @getimagesize($filename);
echo getimagesize($filename);

$newwidth = $width * $percent;
$newheight = $height * $percent;

echo "step";

// Load
//$thumb = imagecreatetruecolor($newwidth, $newheight);
//echo "1 step";
$source= @imagecreatefromjpeg($filename);
$textcolor = imagecolorallocate($source, 0, 0, 255);
imagestring($source, 1, 5, 5, "Error loading $imgname",$textcolor);
//$source = imagecreatefromjpeg($filename);
echo "2 step";

// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
imagejpeg($thumb);
echo "successfully completed";
?>

it returns the following error

getimagesize(\bala\testPHP\Lavanya\Kids2.jpeg): failed to open stream: No such file or directory in /home/bcns/public_html/bala/testPHP/Lavanya/imageprocess.php on line 13
step
Feb 1 '07 #1
Share this Question
Share on Google+
1 Reply


Motoma
Expert 2.5K+
P: 3,235
My php program to resize an jpeg image is as follows,

?php
// File and new size

$filename = '\bala\testPHP\Lavanya\Kids2.jpeg';
//$filename = 'Kids2.jpeg';
$percent = 0.5;

// Content type
//header('Content-type: image/jpeg');

// Get new sizes
list($width, $height) = @getimagesize($filename);
echo getimagesize($filename);

$newwidth = $width * $percent;
$newheight = $height * $percent;

echo "step";

// Load
//$thumb = imagecreatetruecolor($newwidth, $newheight);
//echo "1 step";
$source= @imagecreatefromjpeg($filename);
$textcolor = imagecolorallocate($source, 0, 0, 255);
imagestring($source, 1, 5, 5, "Error loading $imgname",$textcolor);
//$source = imagecreatefromjpeg($filename);
echo "2 step";

// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
imagejpeg($thumb);
echo "successfully completed";
?>

it returns the following error

getimagesize(\bala\testPHP\Lavanya\Kids2.jpeg): failed to open stream: No such file or directory in /home/bcns/public_html/bala/testPHP/Lavanya/imageprocess.php on line 13
step

The slashes '\' are in the wrong direction for your filename. They should be '/'.
[PHP]
$filename = '/bala/testPHP/Lavanya/Kids2.jpeg';
[/PHP]
Feb 1 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.