Very simple PHP script I'm running within an EE template on an Ubuntu Webserver I set up personally.
I know it has something to do with permissions, and I've already changed the owner of the directory I'm trying to write as being the Apache user.
<?php
$dir = 'export';
$drop =' {exp:ajw_export
sql="SELECT member_id, screen_name, email FROM exp_members"
format="xml"
} ';
echo $dir;
file_put_contents($dir, $drop);
?>
Error I get is:
A PHP Error was encountered
Severity: Warning
Message: file_put_contents(export): failed to open stream: Is a
directory
Filename: libraries/Functions.php(689) : eval()'d code
Line Number: 16
Your problem is that you're not defining the actual file, only a directory.
$file = $dir . '/export.txt';
file_put_contents($file, $drop);
Otherwise, how will PHP know where to place the content?
Related
Very simple PHP script I'm running within an EE template on an Ubuntu Webserver I set up personally.
I know it has something to do with permissions, and I've already changed the owner of the directory I'm trying to write as being the Apache user.
<?php
$dir = 'export';
$drop =' {exp:ajw_export
sql="SELECT member_id, screen_name, email FROM exp_members"
format="xml"
} ';
echo $dir;
file_put_contents($dir, $drop);
?>
Error I get is:
A PHP Error was encountered
Severity: Warning
Message: file_put_contents(export): failed to open stream: Is a
directory
Filename: libraries/Functions.php(689) : eval()'d code
Line Number: 16
Your problem is that you're not defining the actual file, only a directory.
$file = $dir . '/export.txt';
file_put_contents($file, $drop);
Otherwise, how will PHP know where to place the content?
Within my script I need to connect to ftp and download few zips files and then extract them in a directory. I have already got this implemented and it works as expected when I run the script through browser but when the crontab run this script it throws me error that it failed to extract file. I tried to research but I had no luck I don't understand the reason for this.
Below is the error that I am getting:
A PHP Error was encountered
Severity: Warning
Message ZipArchive::extractTo(/home/name/files/complete//filename.txt): failed to open stream: Permission denied
Filename: controllers/import.php
Line Number: 66
Script:
$txt_file: "/home/name/files/complete/Data.zip";
$server_txt_file = "/TXT/Data.zip";
if (ftp_get($ftp_conn, $txt_file, $server_txt_file, FTP_BINARY))
{
$zip = new ZipArchive;
if ($zip->open($txt_file) === TRUE)
{
$zip->extractTo('/home/name/files/complete/');
$zip->close();
unlink($txt_file);
}
}
I am trying to fix this for days now but I can not figure out what the issue is.
The error is telling you everything you need to know:
failed to open stream: Permission denied.
So your php process has no permission to write to the specified folder. So you should change the permissions of specified folder.
I have a form and with input type file....what I am trying to do is save that file to the server (in this case, localhost)
move_uploaded_file($_FILES["image"]["tmp_name"], "/admin-uploads/" . $_FILES["image"]["name"]);
and this is the error I get:
Warning: move_uploaded_file(/admin-uploads/home.jpg): failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/Site/admin/Insert.php on line 30
Warning: move_uploaded_file(): Unable to move '/Applications/XAMPP/xamppfiles/temp/phpsoF2wg' to '/admin-uploads/home.jpg' in /Applications/XAMPP/xamppfiles/htdocs/Site/admin/Insert.php on line 30
Am I missing code?
Assuming "/admin-uploads/" directory is a subdirectory of where this script is run. You need the full path to the destination directory.
as:
move_uploaded_file($_FILES["image"]["tmp_name"], __DIR__."/admin-uploads/" . $_FILES["image"]["name"]);
fyi: please be aware that the 'user supplied' [image][name] may not be a valid filename. it may be worthwhile 'sanitizing' it.
I wrote a PHP Application (that works) and I have moved it to a different directory. As a result it needs to get a file from a directory above it, but the file must remain hidden, ie:
Root
--config
---users.xml (Permissions 600)
--lib
----loginUtil.php
I have tried two different methods of getting the file:
$xml = file_get_contents("../config/users.xml");
Which returns the following Error:
[13-Jun-2012 08:54:04] PHP Warning: file_get_contents(../config/users.xml) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: No such file or directory in public_html/test/lib/loginUtil.php on line 18
and
$xml = simplexml_load_file("../config/users.xml");
which returns
[13-Jun-2012 08:56:17] PHP Warning: simplexml_load_file() [<a href='function.simplexml-load-file'>function.simplexml-load-file</a>]: I/O warning : failed to load external entity
I have tried using the full URL, and that works, but I must then make the users.xml file public (as PHP is doing a URL Request).
What can I do to resolve this issue? (Thanks for your help)
try setting the full path and not the relative
$path = '/var/full/path_dir/file.xml';
if(!is_file($path)){
// if this is the is output then you need to check permissions
// double check the file exists also.
// check the web service can read the file
echo "FILE NOT FOUND FOR $path";
}
else{
$xml = file_get_contents($path);
echo $xml;
}
I get an error with my code to receive data from my android app. could someone please resolve my issue with this. I have included the error that I get when I POST the data.
<?php
$filename = "uploads/";
$filename = $filename."data".date.".txt";
file_put_contents($filename, $_POST) ;
?>
Error log:
[14-May-2012 09:49:32 UTC] PHP Warning:
file_put_contents(uploads/datadate.txt) [function.file-put-contents]:
failed to open stream: No such file or directory in
/home/kiwigami/public_html/upload.php on line 27
Make sure that you have a uploads directory under /home/kiwigami/public_html/