I have the following Warnings which SHOULD be there, but is there a way to stop them writting to the page without actually disabling Warnings globally?
Warnings:
Warning: file_get_contents(E:/connected.txt): failed to open stream:
No such file or directory in C:\xampp\htdocs\ppa\test.php on line 19
Warning: file_get_contents(F:/connected.txt): failed to open stream:
No such file or directory in C:\xampp\htdocs\ppa\test.php on line 19
Warning: file_get_contents(G:/connected.txt): failed to open stream:
No such file or directory in C:\xampp\htdocs\ppa\test.php on line 19
Warning: file_get_contents(H:/connected.txt): failed to open stream:
No such file or directory in C:\xampp\htdocs\ppa\test.php on line 19
Warning: file_get_contents(I:/connected.txt): failed to open stream:
No such file or directory in C:\xampp\htdocs\ppa\test.php on line 19
Warning: file_get_contents(J:/connected.txt): failed to open stream:
No such file or directory in C:\xampp\htdocs\ppa\test.php on line 19
Warning: file_get_contents(K:/connected.txt): failed to open stream:
No such file or directory in C:\xampp\htdocs\ppa\test.php on line 19
Warning: file_get_contents(L:/connected.txt): failed to open stream:
No such file or directory in C:\xampp\htdocs\ppa\test.php on line 19
Warning: file_get_contents(M:/connected.txt): failed to open stream:
No such file or directory in C:\xampp\htdocs\ppa\test.php on line 19
Warning: file_get_contents(N:/connected.txt): failed to open stream:
No such file or directory in C:\xampp\htdocs\ppa\test.php on line 19
Warning: file_get_contents(O:/connected.txt): failed to open stream:
No such file or directory in C:\xampp\htdocs\ppa\test.php on line 19
Warning: file_get_contents(P:/connected.txt): failed to open stream:
No such file or directory in C:\xampp\htdocs\ppa\test.php on line 19
PHP Function:
//Check if the connection file is present on each drive
function scanDrives() {
//Possible drives
$letters = "DEFGHIJKLMNOP";
$letters = str_split($letters);
$code = md5("FMbHSBTMTXhu3TWp");
//Check for a certain file on each device
foreach($letters as $x) {
$file = file_get_contents($x.":/connected.txt"); //This is what causes the error as the file can't be found.
if ($file != false) {
$file_code = split(":", $file);
//Check if the file has the correct pass code
if($file_code[0] == $code) {
//Successful, return pass value and device letter and set name
echo (1).",".$x.",".$file_code[1];
}
}
}
}
Thanks.
Don't just blindly open the file with file_get_contents. Check to see if it exists first.
if(file_exists($x.":/connected.txt")){
$file = file_get_contents($x.":/connected.txt");
// ...
}
I agree with #Rocket Hazmat,
but to answer your question - in PHP you can use Error Control operators .. Specifically you can use the # sign to ignore errors.
Simple Example
$file = #file_get_contents("file_doesnt_exist.php"); // wont throw any errors.
Try to put "#" before the function that gives you the warning!
http://us3.php.net/manual/en/language.operators.errorcontrol.php
Related
I am getting below error . I have already tried with dir , document root, require_once and require.
This error i am getting in Live Server.
Warning: include_once(/storage/ssd1/655/2980655/public_html/Lib/DB//MysqliDb.php): failed to open stream: No such file or directory in /storage/ssd1/655/2980655/public_html/index.php on line 8
Warning: include_once(): Failed opening '/storage/ssd1/655/2980655/public_html/Lib/DB//MysqliDb.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /storage/ssd1/655/2980655/public_html/index.php on line 8
Thank you in Advance.
INCLUDE './config/databases.php';
require './vendor/phpmailer/phpmailer/PHPMailerAutoload.php';
When i execute this script from browser i get no warning / issues .
but when i put same script for Cron job
Warning: include(./config/databases.php): failed to open stream: No such file or directory in /home/webdir/public_html/corn_mail.php on line 2
Warning: include(): Failed opening './config/databases.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/webdir/public_html/corn_mail.php on line 2
Warning: require(./vendor/phpmailer/phpmailer/PHPMailerAutoload.php): failed to open stream: No such file or directory in /home/webdir/public_html/corn_mail.php on line 3
Fatal error: require(): Failed opening required './vendor/phpmailer/phpmailer/PHPMailerAutoload.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/webdir/public_html/corn_mail.php on line 3
also tried to change from ./config/databases.php to /home/webdir/public_html/config/databases.php Still the same.
any suggestions ?
Try with removing the ./ - config/databases.php and if the vendor is in same folder then vendor/phpmailer/phpmailer/PHPMailerAutoload.php. No need of ./.
I have a problem with a php code.
Folder name what-counter This folder contains a file with the following php code named counter.php also the hitcount.txt file.
<?php
$filename = '../what-counter/hitcount.txt';
$handle = fopen($filename, 'r');
$hits = trim(fgets($handle)) + 1;
fclose($handle);
$handle = fopen($filename, 'w');
fwrite($handle, $hits);
fclose($handle);
// Uncomment the next line (remove //) to display the number of hits on your page.
echo $hits;
?>
The following php code is used in root directory files also in files from folders which echo's the hits.
<?php include("../what-counter/counter.php"); ?>
The problem
The code works in the files in folders but not in the files that are directly in the root directory.
Example: index.php is in the root directory
Using this code i get this Warning
<?php include("what-counter/counter.php"); ?>
Warning: fopen(../what-counter/hitcount.txt) [function.fopen]: failed to open stream: No such file or directory in /home/what/public_html/what-counter/counter.php on line 4
Warning: fgets(): supplied argument is not a valid stream resource in /home/what/public_html/what-counter/counter.php on line 5
Warning: fclose(): supplied argument is not a valid stream resource in /home/what/public_html/what-counter/counter.php on line 6
Warning: fopen(../what-counter/hitcount.txt) [function.fopen]: failed to open stream: No such file or directory in /home/what/public_html/what-counter/counter.php on line 8
Warning: fwrite(): supplied argument is not a valid stream resource in /home/what/public_html/what-counter/counter.php on line 9
Warning: fclose(): supplied argument is not a valid stream resource in /home/what/public_html/what-counter/counter.php on line 10
And using this code i get this Warning
<?php include("../what-counter/counter.php"); ?>
Warning: include(../what-counter/counter.php) [function.include]: failed to open stream: No such file or directory in /home/what/public_html/include/footer.php on line 31
Warning: include(../what-counter/counter.php) [function.include]: failed to open stream: No such file or directory in /home/what/public_html/include/footer.php on line 31
Warning: include() [function.include]: Failed opening '../what-counter/counter.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/what/public_html
/include/footer.php on line 31
What can i do to the $filename url and <?php include("../what-counter/counter.php"); ?> to get it to work in files in root directory as well as folders?
Either:
Include relative the the file: __DIR__.'/../somefile';/__DIR__.'/somepath/somefile';
Include relative to a known dir: $_SERVER['DOCUMENT_ROOT'] is often used, as is a PROJECT_DIR-like define() in your bootstrap code.
Change the working directory to a known/static dir chdir('/some/dir');. Not recommended as calling code may not expect this.
Sounds like absolute vs relative file problems...
Try replacing:
$filename = '../what-counter/hitcount.txt';
With, depending on where the file is located exactly, either of:
$filename = __DIR__ . '/what-counter/hitcount.txt';
$filename = dirname(__DIR__) . '/what-counter/hitcount.txt';
Or (if you're on an old php install) either of:
$filename = dirname(__FILE__) . '/what-counter/hitcount.txt';
$filename = dirname(dirname(__FILE__)) . '/what-counter/hitcount.txt';
i want to include a file in the header file which is in this directory :
wp-content/themes/themename/header.php
the code i used for inclusion is :
include("../../plugins/booking/informationform.php");
while the file which i want to include is in this directory :
wp-content/plugins/booking/informationform.php
so this gives me an error like this :
Warning: include(../../plugins/booking/informationform.php) [function.include]: failed to open stream: No such file or directory
in
/home/zapptv/domains/tvworkshop.com/public_html/wp-content/themes/tvworkshop/header.php
on line 100
Warning: include(../../plugins/booking/informationform.php)
[function.include]: failed to open stream: No such file or directory
in
/home/zapptv/domains/tvworkshop.com/public_html/wp-content/themes/tvworkshop/header.php
on line 100
Warning: include() [function.include]: Failed opening
'../../plugins/booking/informationform.php' for inclusion
(include_path='.:/usr/local/lib/php') in
/home/zapptv/domains/tvworkshop.com/public_html/wp-content/themes/tvworkshop/header.php
on line 100
but when i copy the file in the same directory where the header is and include it with filename only then it s not giving any error and including successfully.
I am working on something and it is not working. I am getting this error:
Warning: include(../includes/config.php) [function.include]: failed to open stream: No such file or directory in /home/valerie2/public_html/elinkswap/snorris/install.php on line 24
Warning: include(../includes/config.php) [function.include]: failed to open stream: No such file or directory in /home/valerie2/public_html/elinkswap/snorris/install.php on line 24
Warning: include() [function.include]: Failed opening '../includes/config.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/valerie2/public_html/elinkswap/snorris/install.php on line 24
Warning: include(../libs/auth.php) [function.include]: failed to open stream: No such file or directory in /home/valerie2/public_html/elinkswap/snorris/install.php on line 25
Warning: include(../libs/auth.php) [function.include]: failed to open stream: No such file or directory in /home/valerie2/public_html/elinkswap/snorris/install.php on line 25
Warning: include() [function.include]: Failed opening '../libs/auth.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/valerie2/public_html/elinkswap/snorris/install.php on line 25
Fatal error: Call to undefined function phpdighttpvars() in /home/valerie2/public_html/elinkswap/snorris/install.php on line 27
Here is the code that it is getting the error:
24. include $relative_script_path.'./includes/config.php';
25. include $relative_script_path.'./libs/auth.php';
26.
27. extract( phpdigHttpVars(
array('step'=>'integer',
Ok on line 24 where the include is there is a dot I put that in there cause sometimes it will help. But it didn't have one there before and I still had the error. I am not understanding why I can not get these to work. Can someone help me understand?
The actual file it is looking for is
$relative_script_path.'./includes/config.php';
One way to debug is to die with that path, then you can check what it's really looking for:
die($relative_script_path.'./includes/config.php');
The page should stop at that point and display the entire file path. You usually then see what the error could be.