When using the below php code it shows an error
<?php
$path="/hari002244/album/f41b6b54811c.jpg";
$src = imagecreatefromjpeg($path);
?>
It shows
SCREAM: Error suppression ignored for
Warning: imagecreatefromjpeg(/hari002244/album/f41b6b54811c.jpg): failed to open stream: No such file or directory in C:\wamp\www\newEmptyPHP.php on line 3
But when using
<?php
$path="f41b6b54811c.jpg";
$src = imagecreatefromjpeg($path);
?>
It doesn't show any error.
I had typed the path in URL bar and checked whether file exists.It is working perfectly.
Can you tell me why this error occurs? and also how to overcome this?
Thanks in advance.
The first path, "/hari002244/album/f41b6b54811c.jpg" is an absolute path, it starts from the root of the whole file system. Chances are, this path does not exist.
In the second case, it is just a filename "f41b6b54811c.jpg" which is relative to / located in the current working directory, which of course exists.
Got the answer
Instead of "/hari002244/album/f41b6b54811c.jpg"
Should be used "http://localhost/hari002244/album/f41b6b54811c.jpg"
Related
I'm very new here but I'm facing an issue on one of my website with fopen().
$file="//".$_SERVER['SERVER_NAME']."/myfile".date("Ymd").".txt";
if (!file_exists($file)) {
$fp=fopen($file,"w+");
}
$fp=fopen($file,"r+");
And the error message :
fopen(mydomain/myfile20160629.txt): failed to open stream: No such file or
directory in /mydomain/myphpfile.php on line 24
What's funny is that I sometimes get an error message, sometimes not, depending what file use this. And I still got this message when the file is created...
Do you have any idea ?
Try set path : $file="//".$_SERVER['DOCUMENT_ROOT']."/myfile".date("Ymd").".txt";
but before that, move your file in directory $_SERVER['DOCUMENT_ROOT']
I am trying to include a script using the following code.
<div class="main_content">
<?php include ('tweets.php') ?>
</div>
But it keeps throwing up the following error.
Warning: include(tweets.php): failed to open stream: No such file or
directory in - on line 52 Warning: include(): Failed opening
'tweets.php' for inclusion (include_path='.:') in - on line 52
I have checked and double checked and the file definitely exists and is in the same directory as the file that this is in.
I really appreciate your help on this.
The path is relative to the file where the request was initiated.
So, even if it's in the same folder as the file it's including, if that file was included from a file in a different folder, you will have to use an absolute path or a path relative to the original file.
Try using include('./tweets.php');. If that does not resolve your issue, it's most likely file permissions. Give everyone full permissions for tweets.php and see if that works.
As #Josh says, the path is relative to the file that received the request, so you can exploit the PHP __DIR__ magic constant:
include(__DIR__ . '/tweets.php');
1.)if you have 2 different variables is a different scenario like same name one variable with upper case and one variable with lower case...different solution you are right thank you very much
2.)but if someone could change the variables to be complete different variables names they may not have that problem....not always the case
same message but i fix it...cleaning all the blank spaces before and after php symbols <?php and ?>
make sure { and } are not missing and where they need to be
make sure this syntax is correctly where it need to be { and <?php } ?>
No need for an extra path... Thank You very much
Warning: include(tweets.php): failed to open stream: No such file or directory in - on line 52 Warning: include(): Failed opening 'tweets.php' for inclusion (include_path='.:') in - on line 52
That's because your file name not found due to "case sensitive". Example "./Core/admin.php" and "./core/admin.php" are diffrent.
I have a PHP script which reads from an xml file to generate a table. The first thing it does is check to make sure the file exists.
$path = getcwd();
if(file_exists($path.'\inc\php\kbs.xml')){
$kbs = simplexml_load_file($path.'\inc\php\kbs.xml');
} else {
echo "Error: No KB file found";
}
For some reason, intermittently, it doesn't find the file. I've tried removing the file_exists check all together (since I know the file does exist) but it still doesn't load the file at times. I can refresh the page and 7 times out of 10 it doesn't load, but sometimes it does.
I never ran into this problem during development, but once it went production (being used by maybe 200 users now) it started happening.
How do I go about troubleshooting this? (PHP 5.2.14 running on IIS)
EDIT: Error logs give me the following messages when it fails:
Notice: Undefined variable: kbs in <the path> on line 16
Notice: Trying to get property of non-object in <the path> on line 16
Warning: Invalid argument supplied for foreach() in <the path> on line 16
line 16 is the first time the variable $kbs is accessed. Obviously $kbs isn't set if the file isn't found.
Please use the absolute path, relative path make things a mess.
Is the location relative to PHP? Do permissions allow the web server to see it?
I'm getting the following error while uploading a zip archive.
Warning: ZipArchive::extractTo(C:\xampplite\htdocs\testsite/wp-content/themes/mytheme//styles\mytheme/Thumbs.db) [ziparchive.extractto]: failed to open stream: Permission denied in C:\xampplite\htdocs\testsite\wp-content\themes\mythem\uploader.php on line 17
The thing I can't quite figure is that I don't see a thumbs.db file in either the zip archive or the destination folder that was created (the upload still processes, I just get these errors).
The function is below, line 17 is commented...
function openZip($file_to_open) {
global $target;
$zip = new ZipArchive();
$x = $zip->open($file_to_open);
if($x === true) {
$zip->extractTo($target); //this is line 17
$zip->close();
unlink($file_to_open);
} else {
die("There was a problem. Please try again!");
}
}
Looks like just a warning. I would ignore it. I'm betting the error happens when it tried to overwrite the thumbs.db file in the extraction directory.
Alternatively, use getNameIndex to get a list of files, filter thumbs.db and use the second parameter of extractTo to filter the files.
http://www.php.net/manual/en/function.ziparchive-getnameindex.php
http://www.php.net/manual/en/function.ziparchive-extractto.php
This path is all messed up
C:\xampplite\htdocs\testsite/wp-content/themes/mytheme//styles\mytheme/Thumbs.db
I guess this might be windows issue.
can you add a line above line 17 saying
echo $file_to_open; exit;
and tell us what it says when you try to upload file?
Assuming that the mangled path works, then there is a thumbs.db in the destination directory (by default a hidden file), and/or your script does not have permission to write to that file/directory. Windows is very big on spitting out "permission denied" when a file is in use by another process, rather than saying "In use by process XXX".
I am php page everything was working fine till today morning. Now the page is not uploading any selected file. All that I keep getting is the following error message:
Warning: move_uploaded_file(upload/BrainStream_2009_06_25_23041.zip) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\xampp\htdocs\vectorization\admin\jobs_edit.php on line 146
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\Documents and Settings\Admin\Local Settings\Temp\php1B2.tmp' to 'upload/BrainStream_2009_06_25_23041.zip' in C:\xampp\htdocs\vectorization\admin\jobs_edit.php on line 146
File could not be uploaded. Please select a valid file.
File Name:BrainStream.zip
I have written following code:
$uplfile = $_FILES['uploadfile']['name'];
$upltmp = $_FILES["uploadfile"]["tmp_name"];
if(!empty($uplfile))
{
$ext = explode(".", $uplfile);
$upload_date = date("Y_m_d"); //use this variable to change file name to avoid conflict with same name files
$upload_dir = "upload/";
$file_name=$ext[0]."_".$upload_date."_".rand(0, getrandmax()).".".$ext[1];
(move_uploaded_file($upltmp,$upload_dir.$file_name))
}
I have XAMPP stack installed on my PC which is running WinXP, has 3 GB RAM and ample of Hard disk space.
No matter which size file I select it always give error.
What must be wrong in this code?
Interesting syntax in the last line. The error indicates the problem is in that line and either the source file or destination directory is missing. Since the first one is automatically generated, make sure that C:\xampp\htdocs\vectorization\admin\upload exists and is writable.
#phihag,
Thanks for the hint. One of the new developer while studying the source had by mistake remove (../) in the $upload_dir variable assignment.
$upload_dir = "upload/"; //this is wrong
Actually it was set as
$upload_dir = "../upload/"; //this works but accidentally edited by another developer
What a lamer I am. I could not spot the problem.
Anyways thanks once one for your help to solve my problem.
looks like your problem could be that you're using forward slashes for your upload directory but on windows this would be a backslash, you also need to make sure that the upload directory is relative to the script. if not provide a full path.
A good tip to prevent the slashes issue is to use the DIRECTORY_SEPARATOR constant
One of two things - either
There is no upload directory
There is no file php1B2.tmp
This may seem obvious, but be sure to double check your php.ini
file_uploads = On
upload_tmp_dir = "C:\xampp\tmp"
upload_max_filesize = 64M
What might be useful for you to do is a quick check to ensure the file has been uploaded successfully e.g.
switch ($_FILES["cv"]["error"])
{
case UPLOAD_ERR_FORM_SIZE:
// handle error
case UPLOAD_ERR_INI_SIZE:
// handle error
case UPLOAD_ERR_PARTIAL:
// handle error
case UPLOAD_ERR_NO_FILE:
// handle error
case UPLOAD_ERR_CANT_WRITE:
// handle error
}
Its a better way of handling the errors you may encounter when uploading files.