Warning: imagecreatefromjpeg(/web/uploads/orig.jpeg): failed to open stream: No such file or directory in C:\xamppNew\htdocs\photo\thumbimage.class.ph

mallett76

Member
When I run the following code:
<?php
// example.php
#require_once $_SERVER['DOCUMENT_ROOT'].'/common/configs/config_templates.inc.php';
require "thumbimage.class.php";
/* $objThumbImage = new ThumbImage("/web/uploads/orig.jpg");
$objThumbImage->createThumb("/web/uploads/thumb.jpg", 125); */
$objThumbImage = new ThumbImage("/web/uploads/orig.jpeg"); // IMPORTANT - THIS LINE WORKS FINE
$objThumbImage->createThumb("/web/uploads/thumb.jpeg", 125);
?>

I receive the following error
Warning: imagecreatefromjpeg(/web/uploads/orig.jpeg): failed to open stream: No such file or directory in C:\xamppNew\htdocs\photo\thumbimage.class.php on line 12

Warning: imagesx() expects parameter 1 to be resource, bool given in C:\xamppNew\htdocs\photo\thumbimage.class.php on line 13

Warning: imagesy() expects parameter 1 to be resource, bool given in C:\xamppNew\htdocs\photo\thumbimage.class.php on line 14

Warning: Division by zero in C:\xamppNew\htdocs\photo\thumbimage.class.php on line 15

Warning: imagecreatetruecolor() expects parameter 2 to be int, float given in C:\xamppNew\htdocs\photo\thumbimage.class.php on line 16

Warning: imagecopyresampled() expects parameter 1 to be resource, null given in C:\xamppNew\htdocs\photo\thumbimage.class.php on line 17

Warning: imagejpeg() expects parameter 1 to be resource, null given in C:\xamppNew\htdocs\photo\thumbimage.class.php on line 18

Warning: imagedestroy() expects parameter 1 to be resource, bool given in C:\xamppNew\htdocs\photo\thumbimage.class.php on line 19

Warning: imagedestroy() expects parameter 1 to be resource, null given in C:\xamppNew\htdocs\photo\thumbimage.class.php on line 20

The files - like orig.jpeg - in question appear to be there, so, I'm confused by the error.
 
The error message you're encountering suggests that the script is unable to locate the file orig.jpeg in the specified directory.
You can add some debugging statements in your PHP code to output the path being used and verify if it matches the expected path.

<?php
$filePath = "/web/uploads/orig.jpeg";
if (file_exists($filePath)) {
echo "File exists: $filePath";
} else {
echo "File does not exist: $filePath";
}
?>

By checking these steps, you should be able to identify and resolve the issue causing the script to fail to locate the file. i hope it will solve your issue.
 
The error message you're encountering suggests that the script is unable to locate the file orig.jpeg in the specified directory.
You can add some debugging statements in your PHP code to output the path being used and verify if it matches the expected path.

<?php
$filePath = "/web/uploads/orig.jpeg";
if (file_exists($filePath)) {
echo "File exists: $filePath";
} else {
echo "File does not exist: $filePath";
}
?>

By checking these steps, you should be able to identify and resolve the issue causing the script to fail to locate the file. i hope it will solve your issue.
Thank you, I will give your suggestion a try.
 
In the followng folder, C:\xamppNew\htdocs\photo I created the following file fileExistsTestNew.php

Which has the following code:

<?php
$filePath = "/web/uploads/orig.jpeg";
if (file_exists($filePath))
{
echo "File exists: $filePath";
}
else
{
echo "File does not exist: $filePath";
}
?>

And I'm confused, because it said the file doesn't exist. However, the orig.jpeg is in the following location

C:\xamppNew\htdocs\photo\web\uploads\orig.jpeg

So, do you know what I'm doing wrong?
 
Yes, it seems like you're providing an incorrect file path. When you specify $filePath = "/web/uploads/orig.jpeg";, PHP interprets it as an absolute path starting from the root directory of your filesystem. In this case, it's trying to find the file at C:\web\uploads\orig.jpeg, which doesn't exist based on your provided directory structure.
To fix this, you need to provide the correct relative path from the location of your PHP file to the orig.jpeg file. Since your PHP file fileExistsTestNew.php is located in C:\xamppNew\htdocs\photo, you should adjust your $filePath variable accordingly:

$filePath = "web/uploads/orig.jpeg";

This path is relative to the directory of your PHP file and should correctly point to C:\xamppNew\htdocs\photo\web\uploads\orig.jpeg.
Make sure that the file exists at that location relative to your PHP file, and your code should work as expected.
 
Back
Top