Require path is not being accepted [closed] - include

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
Warning:
require_once(/var/www/html/test_lms/include/mysql.processing.php):
failed to open stream: No such file or directory in
/var/www/html/test_lms/include/IMEXporter.class.php on line
513
Fatal error: require_once(): Failed opening required
'/var/www/html/test_lms/include/mysql.processing.php'
(include_path='.:/usr/local/lib/php') in
/var/www/html/test_lms/include/IMEXporter.class.php on line
513
PHP from IMEXporter.class.php LINE 513 that is throwing the error
require_once dirname(__FILE__) . "/mysql.processing.php";
The file is there.
The file is chmod 777.
The two files are both owned by the same user and group.
Why is php doing this to me?
The problem could be that mysql.processing.php itself is broken and even though php finds the file it refuses to retrieve it and instead throws a Derp! cant find file. Derp.. Kind of stupid to mislead me like that but its a possibility. I'm checking over my code now.
Nope, I tried erasing the entire script of mysql.processing.php and wrote
echo "Hello you impudent php";
and it still wont find the file. So its not a file broken issue. Also I fixed the file case issue. From uppercase P to lowercase and it still wont go for it. I tried to include a file by the name of test.php and it wont find that one either..

You are having case sensitivity issue. Most likely you moved form windows environment to Linux
If your file is mysql.processing.PHP require_once dirname(__FILE__) . "/mysql.processing.php would work on a windows + apache server but fail on Linux + apace
use the following to get the actual file name
var_dump(scandir(__DIR__));
Please run this simple test
error_reporting(E_ALL);
$name = "mysql.processing.php";
$file = __DIR__ . "/mysql.processing.php";
$dir = scandir(__DIR__);
$func = array("file_exists","is_file","is_readable");
echo "<pre>";
foreach ( $func as $fun ) {
if (! $fun($file)) {
echo $fun, " - Failed ", PHP_EOL;
} else {
echo $fun, " - Failed ", PHP_EOL;
}
}
if (! in_array(basename($file), $dir)) {
echo basename($file), " in_array Error", PHP_EOL;
} else {
echo basename($file), " in_array OK", PHP_EOL;
}
if (! in_array($name, $dir)) {
echo $name, " in_array Failed", PHP_EOL;
} else {
echo $name, " in_array Ok", PHP_EOL;
}
if ($name !== basename($file)) {
echo $name, " basename Failed", PHP_EOL;
} else {
echo $name, " basename OK", PHP_EOL;
}

Well, in the error message the capitalization on the filename is not the same as in the require line you posted... are you sure it's not a typo?

Okay here was the problem. Remember when I mentioned that my mysql.processing.php file could be broken? Well that was half the issue. Apparently php require returns the error failed to open stream: No such file or directory.. etc if it:
1) Cannot find the file.
2) It finds the file, but it cannot open it.
The error message is misleading and leads you to believe it is a path issue. Sometimes it is, but cases like mine, its just a syntax issue with the returned file. Now for the second half. I made the corrections to all my syntax errors on the mysql.processing.php but it still was not working.. So I just did a reboot of my server and now it works.
The second half of the problem is that php has a nasty tendency to cache php files. Often you can start editing a php script, fixing solutions etc etc and not make any progress because php wont immediately take into effect your changes. This can lead you into stumbling around from one solution to the next, constantly changing your script and it can feel like you are in a maze.
There are ways to stop php from caching specific files. But the problem was php itself, with its misleading error report, and two with its caching of problems and excluding solutions.

Maybe the problem is that your php are not in the same folder, you cannot include a .php from a URL or another folder. You can include a php if it is on the same path or in a subfolder that is on your path. Sorry for my english but I think that you're going to understand what I'm saying.

Related

Terraform GCP Instance Metadata Startup Script Issue

I've been working with Terraform, v0.15.4, for a few weeks now, and have gotten to grips with most of the lingo. I'm currently trying to create a cluster of RHEL 7 instances dynamically on GCP, and have, for the most part, got it to run okay.
I'm at the point of deploying an instance with certain metadata passed along to it for use in scripts built into the machine image for configuration thereafter. This metadata is typically just passed via an echo into a text file, which the scripts then pickup as required.
It's... very simple. Echo "STUFF" > file... Alas, I am hitting the same issue OVER AND OVER and it's driving me INSANE. I've Google'd around for ages, but all I can find is examples of the exact thing that I'm doing, the only difference is that theirs works, mine doesn't... So hopefully I can get some help here.
My 'makes it half-way' code is as follows:
resource "google_compute_instance" "GP_Master_Node" {
...
metadata_startup_script = <<-EOF
echo "hello
you" > /test.txt
echo "help
me" > /test2.txt
EOF
Now the instance with this does create successfully, although when I look onto the instance, I get one file called ' /test.txt? ' (or if I 'ls' the file, it shows as ' /test.txt^M ') and no second file.. I can run any command instead of echo, and whilst the first finishes, the second+ does not. Why?? What on earth is causing that??
The following code I found also, but it doesn't work for me at all, with the error, 'Blocks of type "metadata" are not expected here.'
resource "google_compute_instance" "GP_Master_Node" {
...
metadata {
startup-script = "echo test > /test.txt"
}
Okaaaaay! Simple answer for a, in hindsight, silly question (sort of). The file was somehow formmated in DOS, meaning the script required a line continuation character to run correctly (specifically \ at the end of each individual command). Code as follows:
resource "google_compute_instance" "GP_Master_Node" {
...
metadata_startup_script = <<-EOF
echo "hello
you" > /test.txt \
echo "help
me" > /test2.txt \
echo "example1" > /test3.txt \
echo "and so on..." > /final.txt
EOF
However, what also fixed my issue was just 'refreshing' the file (probably a word for this, I don't know). I created a brand new file using touch, 'more'd the original file contents to screen, and then copy pasted them into the new one. On save, it is no longer DOS, as expected, and then when I run terraform the code runs as expected without requiring the line continuation characters at the end of commands.
Thank you to commentors for the help :)

Bash: What does "file < FILE > FILE.extension &" means?

I was running AutoPhrase and after running it's auto_phrase.sh shell script, I am getting the following error:
After backtracing it's source, I found this line (line 32) which is causing the above mentioned error.
All I know is it is doing something like:
file < FILE > FILE.extension
However, I failed to understand what is happening in this line.
Can someone could explain it to me ? And how may I resolve this issue ?
The problem here seems to be that ./bin/tree-tagger does not exist. Note that ./bin is not the same as /bin.
That being said, the answer to your question of what file < FILE > FILE.extension does is unrelated, but these are redirects in bash. FILE is piped < into the $STDIN of file and the output is directed > to the file FILE.extension.
Locate ./bin/tree-tagger by installing it or redirecting its path appropriately to resolve the error.
As for the actual question in the title, the command means
./cmd/tree-tagger-english run this command ...
< ... with standard input from ...
$f ... an (incorrectly unquoted) variable which should contain a file name ...
> ... with standard output redirected to ...
$f.tagged ... a file named by the (still incorrectly unquoted) value of $f with the string .tagged appended at the end ...
& ... as a background job.
Apparently ./cmd/tree-tagger-english in turn attempts to execute a command which doesn't exist, many times.
Probably the instructions tell you to run the thing in a different directory than where you are actually running this; but this is obviously merely a speculation. Another fairly common scenario is that something failed during installation, but you failed to notice (and so some files which should exist in these locations do not actually exist ... disk full? Wrong permissions?)
The fact that the code contains quoting bugs suggests that it's also quite possible that the code is simply buggy.

Wrong controller function getting called

I'm building a small HR management system for my company, and am facing a weird issue with GoDaddy hosting. As if the pain that comes with figuring out the index.php? part was not enough, now I'm not able to log in as an HR. The error I get is that:
Parse error: syntax error, unexpected '[' in /home/content/37/11019837/html/hrms/application/controllers/hr.php on line 58
Now the line it refers to is part of a file upload function, and goes like this:
$path = $this->upload->data()['full_path'];
. . . which is simply saving the uploaded file path to $path. BUT, this is part of the uploading function and shouldn't even be accessed while logging in. Once I hit "Log in", the URL says http://www.example.com/hrms/index.php?/hr/dashboard which means the following function will be called:
public function dashboard()
{
$data['page_title'] = 'HR Area';
$this->load->view('hr/header.php', $data);
$this->load->view('hr/navigation.php');
$this->load->view('hr/footer.php');
}
A parting note: The app is working without hiccups on the local server, so I'm not sure why it's hopping functions on GoDaddy servers. Can someone throw some light?
Try this:
$path = $this->upload->data();
$path1 = $path['full_path'];

Simulating sendmail with dummy script

I created a small shell script which logs all of it's input to a log file, with which I had thought I could replace the sendmail binary and thus achieve a simple way to simulate e-mail delivery without actually setting up a working sendmail.
This failed, however. For reasons I cannot understand.
I've looked at the PHP mail.c source and as far as I can understand (mind you, I'm not very experienced in C), PHP executes and talks directly to the binary (set in sendmail_path). But no log files are being created when I replace the sendmail binary with my script and the script replacing sendmail will always create a log file when it's executed, regardless of if there's input present or not.
The script itself works fine. Its' return codes should conform to that of sendmail's. With the difference that my script always returns 0, regardless of the input, since I'm not really interested in checking if the input is valid - just that I'm getting some.
Is it possible to achieve what I want, i.e. using a sendmail simulator?
The script source is provided below:
#!/bin/bash
LOGDIR=/tmp/sendmail-sim
NOW=$(date +%Y%m%dT%H%M)
CNT=1
FILENAME="$LOGDIR/$NOW.$CNT.log"
while [ -f $FILENAME ]; do
CNT=$(($CNT + 1))
FILENAME="$LOGDIR/$NOW.$CNT.log"
done
echo "$0 $*" > $FILENAME
while read BUF
do
echo $BUF >> $FILENAME
done
exit 0
PS. My current sendmail (or actually, postfix) does receive email from PHP, but I don't want to actually send any email or need to go digging in its' mail queue in development.
The problem was User Error, as usually. So, boys and girls, don't forget to check write permissions on all the relevant folders.
I've used Fakemail for this purpose in the past. It accepts SMTP connections but writes all mail to files rather than sending them along as email. There are both python and perl implementations.
http://www.lastcraft.com/fakemail.php
We setup apache to serve the directory that Fakemail was writing to. That was a quick and easy way for staff to view the messages that Fakemail was receiving and review for content, destination, etc. Formatting of HTML emails was a bit whacky for various reasons, so it was not so useful for vetting formatting of html emails.
If you need to to test you PHP application's ability to properly format and send email without actually sending them, I suggest you use the Pear Mail package. Fiddling with your system is not a good idea.
If you use Mail from Pear you could switch from sendmail to smtp to a mock implementation of the mail interface by changing the driver from 'sendmail' or 'smtp' to 'mock'.
http://pear.php.net/package/Mail/docs/latest/Mail/Mail.html
http://pear.php.net/package/Mail/docs/latest/Mail/Mail_mock.html
If your code looks like this:
mail('me#example.com', 'My Subject', $message);
Then change it to be testable using PEAR Mail:
include('Mail.php');
function sendEmail($recipient, $subject, $body, $driver = 'mail') {
$m = Mail::factory("mail");
$headers = array(
"From"=>"me#example.com",
"To" => $recipient,
"Subject"=> $subject);
$m->send($recipient, $headers, $body);
return $m;
}
// In Production:
sendEmail('me#example.com', 'My Subject', $message);
// During testing:
$m = sendEmail('me#example.com', 'My Subject', $message, 'mock');
var_dump($m->sentMessages);
This is very crude, since you should be using PHPUnit or SimpleTest, but this is a topic for another time and place :)
A note, if you just want to grab stdin and write it into a file, you don't need to loop one line at a time: you can write
cat - >> $FILENAME

Write permissions with Codeigniter + Simplepie

I am trying to create a simple RSS parser using the two frameworks. However I am getting PHPerrors when trying to write to my cache directory:
set_cache_location(APPPATH.'cache/rss');
I am running windows 7 with XAMPP using the latest version of Simplepie from github
error:
A PHP Error was encountered
Severity: User Warning
Message: C:\xampp\htdocs\geekurls/system/application/cache/rss is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.
Filename: libraries/simplepie.php
Line Number: 1732
Tried like the below comment said and tried making a test file but to no luck
$file = APPPATH."cache/rss/testFile.txt";
$handle = fopen($file, 'w') or die("fail");
fclose($handle);
A simple checks to find out what might be happening,
Try creating a file in this directory using standard php - this could help solve permission problems.
$this->load->helper('file');
$data = 'Some file data';
if ( ! write_file('./path/to/file.php', $data))
{
echo 'Unable to write the file';
}
else
{
echo 'File written!';
}
Also how about using the default cache?
http://simplepie.org/wiki/faq/i_m_getting_cache_error_messages

Resources