php POST data and saving it - php

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/

Related

file_put_contents(): read of 8192 bytes failed with errno=21 Is a directory [duplicate]

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?

PHP Zip Archive Extract Not working When Script is Executed by Crontab

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.

PHP failed to open stream: Is a directory

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?

failed to open stream : Is a directory in

I am getting the following warnings on trying on move an uploaded file from the temp folder to the desired one using php
Warning: move_uploaded_file(test/) [function.move-uploaded-file]: failed to open stream: Is a directory in /home/..../filename.php on line 69
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpKrCpQw' to 'test/' in /home/..../filename.php on line 69
following are line nos 67 and 69 that are giving the error :
$destination = "test/". $name;
$answer = move_uploaded_file($_FILES['user_file']['tmp_name'],$destination);
It seems like your name is null
$destination = "test/". $name;
echo you name and see what is coimg there.
For me, it was the filesize.
So, check php.ini to see if the uploaded file exceeds upload_max_filesize and post_max_size.
Or maybe add a validation rule in Laravel or js.

PHP XML Get Error

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;
}

Categories