Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 256
Palak Taneja Avatar asked Jan 28 '13 11:01

Palak Taneja


People also ask

What does failed to open stream mean?

PHP - Failed to open stream : No such file or directory. In PHP scripts, whether calling include (), require (), fopen (), or their derivatives such as include_once, require_once, or even, move_uploaded_file (), one often runs into an error or warning: Failed to open stream : No such file or directory.

Why can't I open PHP stream?

PHP - Failed to open stream : No such file or directory 1. Check the file path for typos either check manually (by visually checking the path) or move whatever is called by... 2. Check that the file path is correct regarding relative vs absolute path considerations if it is starting by a forward... ...

Why can't PHP open a file outside the specified directory?

If none of the above worked, then the issue is probably that some PHP settings forbid it to access that file. Three settings could be relevant : If this is set PHP won't be able to access any file outside of the specified directory (not even through a symbolic link). if this is turned on restrictions might apply.

Who owns the files in a shared directory?

That user owns the file and possibly the parent directory (especially the parent directory if you want to write files). In most shared hosting environments this won't be an issue, because your user should own all the files underneath your root.


2 Answers

It seems like your name is null

$destination = "test/". $name;

echo you name and see what is coimg there.

like image 68
Prasanth Bendra Avatar answered Oct 28 '22 19:10

Prasanth Bendra


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.

like image 43
mayid Avatar answered Oct 28 '22 18:10

mayid