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.
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?
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 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/
I have already created directory at location 'cms/user/prescriptionimg' But I am getting error in uploading file.
Warning: move_uploaded_file(../cms/user/prescriptionimg/11500004-21000002-13165874331.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/oxfordmo/public_html/cms/user/prescription.php on line 113
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpdCWdaR' to '../cms/user/prescriptionimg/11500004-21000002-13165874331.jpg' in /home/oxfordmo/public_html/cms/user/prescription.php on line 113
Unable to move user 11500004-21000002-13165874331's picture to prescription directory
Script regarding this is...
if (file_exists("../cms/user/prescriptionimg/$username.$ext"))
{unlink("../cms/user/prescriptionimg/$username.$ext"); }
if (!move_uploaded_file($_FILES["scaninput".$i]['tmp_name'],"../cms/user/prescriptionimg/$username.$ext"))
{ die("Unable to move user $username's picture to prescription directory"); }
use this function to retrieve root path.
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
//-----------------------------------
// require the functions file
//-----------------------------------
//require ("$root/php/funkshions.php");
using this line
$file_move = move_uploaded_file($_FILES['uploadedfile']['tmp_name'],
plugins_url('/css', __FILE__));
returns:
move_uploaded_file(http://localhost/*) [function.move-uploaded-file]: failed to open stream: HTTP wrapper does not support writeable connections in /Applications/MAMP/htdocs/***/as_settings.php on line 60
I have checked both arguments, and they are correct. I'm new to this side of coding, what have I missed?
---EDIT
In response to answers, have changed code to:
$dir = ABSPATH . 'wp-content/plugins/app-switcher/css';
$file = $_FILES['uploadedfile']['tmp_name'];
$file_move = move_uploaded_file($file,$dir);
Now my error response is:
Warning: move_uploaded_file(/Applications/MAMP/htdocs//wp-content/plugins/app-switcher/css/) [function.move-uploaded-file]: failed to open stream: Is a directory in /Applications/MAMP/htdocs//wp-content/plugins/app-switcher/as_settings.php on line 61
The error message is pretty obvious, your destination file should be a path, not a URL
You can't use a http:// URL as the target for move_uploaded_file(). You need to use a file path.
You're not saying what framework you are using, but it may have a counterpart to plugins_url() that returns a file path.
second parameter should not be URL
It's still obvious.
you have to pass a filename, not directory to this function