I have what should be a fairly straightforward operation, which gives me an error that doesn't seem very helpful. The code is this:
<?php
$strLines = file('//tardis/htdocs/apps/freespace/FreeSpace-Servers.txt');
.
.
.
?>
But in php-errors.log, I get this:
[28-Aug-2013 16:31:30] PHP Warning: file(//tardis/htdocs/apps/freespace/FreeSpace-Servers.txt) [function.file]: failed to open stream: Invalid argument in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\apps\freespace\freespace.php on line 2
The txt file is definitely there. Any ideas what else an "Invalid argument" might suggest? The documentation doesn't seem to hint at much of anything else. Or, should I be doing this a different way? My goal is to read the file in as an array of things. All help is appreciated.
If you're using UNC, then the address should be
file('\\\\tardis\\htdocs\\apps\\freespace\\FreeSpace-Servers.txt');
You may also need to check that your PHP configuration allows you to open remote files.
I have a somewhat more correct answer than any of the above. While all of the above is completely right, the actual problem (and solution) is detailed on question 18748985: PHP fails to read files.
The short answer is: The Apache user password was changed, but Apache didn't know about it. Update the password and restart the service. The overall problem is slightly more colorful than that, but that's how the issue is most succinctly reduced.
Related
I am new to PHP. I am trying to send email through PHP.
The error I got while sending is:
[23-Sep-2014 15:31:08 UTC] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20100525/ixed.5.2.lin' - /usr/local/lib/php/extensions/no-debug-non-zts-20100525/ixed.5.2.lin: cannot open shared object file: No such file or directory in Unknown on line 0
[23-Sep-2014 15:31:08 UTC] PHP Fatal error: Directive 'allow_call_time_pass_reference' is no longer available in PHP in Unknown on line 0
cannot open shared object file: No such file or directory in Unknown on line 0
I don't know how to solve this. I browsed a lot they said some suggestions.
I am new to PHP and I can not find the solution(s) for this.
Hope you guys help me to complete my first PHP task successfully...
Thanks in advance...
EDIT : Sorry friends even hello world is not working.. I dont know what to do now whether iwant to install anything... Forgive me for asking very silly questions.. Though am very new am struggling..
Check if /usr/local/lib/php/extensions/no-debug-non-zts-20100525/ixed.5.2.lin really exists.
(i guess it does not)
After that, you should find it:
locate ixed.5.2.lin
and put it into the location your php is looking for.
(/usr/local/lib/php/extensions/no-debug-non-zts-20100525/)
If locate does not give any results, you have to install the missing library ...
Remark: to do locate, you will need a console, preferrably with root access.
Edit: Also please check if a simple print('hello'); would work, if not, you should fix your PHP install first.
Check if the binary exists in extension directory on the server OR the extension directory is correctly defined in php.ini. These are the possibilities which is causing problems. Also try setting permissions to 755 on ixed.5.2* once and see if that makes the trick.
Thank you so much for all who spent your time to take part in my issue.
I solved that by contacting my server person..
There is some issue in my curl file, One ; is missed out in that.
Now everything works fine..
Special Thanks for Gipsk Jakab .... His answer narrowed my prob...
I need to read some meta information from the downloaded file. But I do not know how to do it.
Here is my code:
// Path form field_file
$file = 'public://directory/filename.txt';
file_get_contents($file);
This code causes this warning:
Warning: file_get_contents(): Unable to find the wrapper "public" - did you forget to enable it when you configured PHP?
Any idea of what I am doing wrong, please?
There are three internal stream wrappers private, public and temporary, they are defined in this file.
You may want file_get_mimetype(), file_get_contents is a PHP function and won't be aware of the drupal file api.
file_get_contents(drupal_realpath($file));
Would do the trick for reading.
For an upload take a look at file_save_upload()
I believe that these wrappers aren't available in hook_boot() or some other early stages.
So please move your code into another place and check if this would fix the problem.
The fix I'm using is the following code:
echo base_path().variable_get('file_public_path',conf_path().'/files');
It still doesn't explain why streams aren't working.
I am running the code below in some if/else statements, I have a weird issue in the same file this exact code below works fine, however in another area if it is called I get this error;
Warning: include() [function.include]: URL file-access is disabled in the server configuration in C:\webserver\htdocs\processing\process.friends.php on line 168
Warning: include(http://localhost/index.php) [function.include]: failed to open stream: no suitable wrapper could be found in C:\webserver\htdocs\processing\process.friends.php on line 168
$_SESSION['sess_msg'] = 'Please Enter the Correct Security Code';
$_GET["friendid"] = $friendid;
$_GET["p"] = 'mail.captcha';
$_GET["f"] = 'friend';
include ("index.php");
exit;
And just to clarify I am njot trying to run this code 2 times at the SAME time, it's more like this; Not just like this but you get the point that they are not run at the same time
if(something){
run the code above
}else{
run the code above
}
If it matters, I am currently running a LAMP setup on a windows PC
remove the "http://localhost" part of your code. As a rule of thumb, when you include your own files, you should include them from your file system.
include "./index.php";
Just remove the http://localhost/ part and you'll be okay.
Well, I don't kow the answer to your question, though I do have to ask why you feel the need to include a URL based file?
include('http://whatever.com/'); can be EXTREMELY dangerous.
If you're just trying to output the HTML generated from that, I'd suggest you do something like echo file_get_contents('http://some/url');. If you're trying to include PHP code, use the system path
Are they EXACTLY the same? Could you post both versions of the code?
I can also recommend not doing an include('http://...'); This will make PHP to an HTTP request to your webserver, and grab the result. You might be a bit better off just doing include('index.php');, if this is possible for your setup.
Is allow_url_fopen enabled in php.ini?
I'm debugging some PHP code written by an outsourcing company (I'm not a PHP guy at all but know the basics; we have an offshore team of PHP developers working for us on this project) that's not working; the code is supposed to be called every 30 minutes by a cron job but its not firing. I tried to run the PHP script via the command line to test if it's working, but it's giving me the following (anonymized) errror:
PHP Fatal error: require_once(): Failed opening required '/myapp/_lib/_classes/MySql.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/myapp/_lib/_base/common.inc.php on line 6
However, the file /var/www/html/myapp/_lib/_classes/MySql.php exists under the proper directory. I'm missing something simple, I'm sure, but like I said I know really nothing beyond the bare basics of PHP and I really need to get this service up and running.
EDIT: The code is using the __autoload() function with all classes in /_lib/_classes
if you start a file name with a slash, it means it's an absolute path. try instead:
require_once('/var/www/html/myapp/_lib/_classes/MySql.php');
Case sensitivity maybe? I've had that problem before.
I'm guessing it's a permissions issue - make sure both your account (for testing purposes) and whatever account cron is going to run your script under (quite possibly yours, but maybe a different one) have read privileges on the file.
Also: the path for the include says /myapp/_lib/_classes/MySql.php, whereas it exists in /var/www/html/myapp/_lib/_classes/MySql.php. Can you change the include to reference the full path?
As said, casing and in addition the correct permissions to access that file are needed.
I am currently using an image manipulation script to do some work on uploaded images and I'm running into a problem in my dev environment. This same code works on my production server.
The error is:
PHP Warning: imagecreatefromjpeg(): php_network_getaddresses:
getaddrinfo failed: Name or service not known in /path/to/script.php
on line 75
The line of code on 75 is:
$this->img = imagecreatefromjpeg(PHPTHUMB."?src=/".$this->image_path);
which creates an image that is loaded from another made by phpThumb, which is used for further manipulation.
Any ideas on how to solve this? Can anyone shed some light on what the error means?
Thank you,
Edit:
Just as a further bit of insight, if i visit PHPTHUMB . "?src=/" . $this->image_path in my browser, the image loads fine
User agent in php.ini did not solve the problem as indicated here
EDIT (SOLUTION): I had to add the INTERNAL 192.168.204.XXX IP into the hosts file, so that http://dev.mysite.com resolved correctly. Trying both 127.0.0.1 and the external IP yielded no result, but the internal works perfectly. Thanks for everyone's efforts,
I'm totally not sure about the cause of that error, but this is my best guess.
There is a particular PHP Setting which enables you to treat URLs as files. Normally imagecreatefromjpeg accepts a filename, I think. Since you are passing a URL, you need to make sure the particular setting is enabled. I believe you can find more info about it here: http://us2.php.net/file
filename
Path to the file.
Tip
A URL can be used as a filename with this function if the fopen
wrappers have been enabled. See
fopen() for more details on how to
specify the filename and List of
Supported Protocols/Wrappers for a
list of supported URL protocols.
Fopen wrappers: http://us2.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen
Your dev environment may not be setup with this, but your production environment could be.
Edit
This page lists your error:
http://bugs.php.net/bug.php?id=11058
and mentions that a possible fix is by modifying your hosts file to explicitly include the ip/dns of the server you're accessing.
i tryed to reconfigure my named
configuration, without any result, to
fix this. the problem was solved by
adding the following line to my
/etc/hosts:
194.97.55.147 mx.freenet.de
Maybe you can try this?
did you also check that allow_url_fopen is set to On in php.ini?
I saw that they did mention that in the article you referred to in your post.
EDIT: Also, what OS and what PHP version are you running?
Just read this on php.net: "On Windows versions prior to PHP 4.3.0, the following functions do not support remote file accessing: include(), include_once(), require(), require_once() and the imagecreatefromXXX functions in the GD Functions extension."
EDIT2:
I just read what was written in the comments, your allow_url_fopen is set to On, sorry about that.
But OS, PHP version and phpinfo() would help in finding the problem.
The error message suggests something is wrong at a networking level. Thus, if possible, bypass that. Try using the path to the thumbnail generator, instead of a network address.
If that's not an option, try something that will give you more granular error messages. I suggest CURL. At the very least, it should yield a more informative error message.
The simple fact that this is failing is because on your webserver, your DNS resolution is broken.
If you have SSH access to your server, try the following command
dig hostname
where hostname is the host name from PHPTHUMB
This will probably fail.
Assuming that you're using Linux, my suggestion would be to edit your /etc/resolv.conf (as root)
and add the following line before any other lines beginning with "nameserver"
nameserver 4.2.2.2
This should hopefully fix things, though you may have to restart apache (or whatever webserver you're using)!
The issue here is that php fails to resolve the url that you provide as PHPTHUMB as stated in this bug report on php.net. This possibly means that it's the fault of the operating system/web server, in which case you can enter the ip address of the server you are connecting to into your hosts file manually.