Wordpress using file_get_contents in functions.php? - php

I'm trying to open a .p12 key file I placed in the same directory as functions.php. I tried using file_get_contents() to open the file, I also tried opening other random files and found that I could not.
PHP Warning: fopen(key.p12) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: No such file or directory in path/wp-content/themes/theme-name/functions.php on line 26
I've been trying to get around this for hours.

Doesn't matter that functions.php and key.p12 are in the same directory. It all matters what the running script's working directory is. e.g.
/maindir/subdir/functions.php
file_get_contents('key.p12');
/maindir/script.php
include('subdir/functions.php');
In this case, the working directory will be maindir, and f_g_c() will be doing the equivalent of file_get_contents('/maindir/key.p12'), and fail, because the file is NOT in maindir.
Check getcwd() at the point you're doing the file_get_contents() call, and check what the working directory really is at that point. You'll probably find it's something completely different than the dir that functions.php lives in.

Related

Why is my PHP copy() function creating a blank file?

I have a copy function per say:
<?php
copy ( "$source" , "$destination" );
?>
The code does create a copy succssfully however the $destination (or copied file) is left blank. if i open it it is empty unlike the $source file.
The file size is 0b.
My situation:
nginx/1.10.0 (Ubuntu)
PHP 7.0.13-0
ubuntu0.16.04.1
The file permissions for the code processing file is 0777
The permission for the source file is 0777
The file permission for the destination file after being copyed (the blank one ) : 0644.
Obviously no control over the permission before copying.
Anyone know the reason for this and how to make the php copy() function copy the file with the original file contents?
Best regards,
AT
Ok so i seemed to solve this apparently my server ran out of disk space.
Makes sense. should have known.

wordpress copy plugin uploaded file to theme dir

I have a line of code that is supposed to copy image from one directory to another:
copy("http://localhost:8080/wordpress/wp-content/uploads/2015/06/uploaded_background.jpg","http://localhost:8080/wordpress/wp-content/themes/landing-page/img/desktop-background.jpg");
This is located in wordpress theme header.php file, however I am receiving an error message:
Warning:
copy(http://localhost:8080/wordpress/wp-content/themes/landing-page/img/desktop-background.jpg):
failed to open stream: HTTP wrapper does not support writeable
connections in
C:\wamp\www\wordpress\wp-content\themes\landing-page\header.php on
line 42
Line 42 is where my copy function line is located.
How can I solve this issue. Any suggestions or links would help a lot.
instead of using
copy("http://localhost:8080/wordpress/wp-content/uploads/2015/06/uploaded_background.jpg","http://localhost:8080/wordpress/wp-content/themes/landing-page/img/desktop-background.jpg");
try
copy`("/yourserverfolderpath/wordpress/wp-content/uploads/2015/06/uploaded_background.jpg","/yourserverfolderpath//wordpress/wp-content/themes/landing-page/img/desktop-background.jpg");`
yourserverfolderpath/ could be something like /home/user/abc/
see you ftp or cpanel for exact path
see this SO question as guideline
PS:
In case of local file, path would be something like D:\php\www\www\xml.php
as pointed by #dlegall in comments and as per documentation, First param of copy() can be a valid URL, see the docs here
You should use a local path as a 2nd parameter to copy(), since http protocol does not support file overwriting.
The destination path. If dest is a URL, the copy operation may fail if the wrapper does not support overwriting of existing files.
Source : http://php.net/manual/en/function.copy.php

MPDF dejavuserifcondensed.mtx.php No such file or directory

Can someone help me with this I am getting the following message when trying to use MPDF
include(/var/www/svn_data/skeletonapp/mpdf/ttfontdata/dejavuserifcondensed.mtx.php): failed to open stream: No such file or directory
I have chmod'ed the correct files ttfontdata, tmp and graph_cache
It seems like the system has to generate the files but its not.
Thanks,
Ross.
The problem is that directory ttfontdata/ is not writable for the process under which the PHP code is running. MPDF needs to generate and write some files there.
Simplest solution is:
chmod 777 ttfontdata

php fopen can't find file that definitely exists

I'm trying to load data from a CSV on my Windows PC into a database, something I've successfully done previously. fopen can't find my input file.
Here's the specific code I'm having trouble with:
<?php
ini_set('track_errors', '1');
$handle = fopen("C:/Users/Sam/Documents/test.csv", 'r') or die("can't open file: $php_errormsg");
?>
The error printed is:
[function.fopen]: failed to open stream: No such file or directory
The file definitely exists, and I get the same problem on Unix machines. How do I fix this?
Windows 7 (and Vista?) only lets a user access his own home directory and does not allow Apache (or other users) to. Unfortunately, this is a major headache, and I would suggest that you just move the file somewhere public.
This type of behavior is easier to fix in Linux, but you're still better off moving the file out of your directory into some path where Apache has read access.

.PHP files with .TXT includes (Code Display Error)

So I am using .php pages now to use a .txt include for the navigation.
Here is the live page I am working on :
http://glustik.com/essex/index.php
It seems to display line 27 code errors, not sure how to get this include to work.
Anyone care to point me in the right direction for this one?
Warning: include(txt) [function.include]: failed to open stream:
No such file or directory in /home/hletf/public_html/essex/index.php on line 27
Is your problem already stated there? There is an error since include(txt) is NOT a right inclusion of a file. Create your *.txt file first and then include it. Something like include("foo.txt")
If you want files .txt to be parse as .php files you should change your apache configuration, or write your own class which will parse this file and return value that you need

Categories