0

I have been following a set of tutorials in thenewboston [PHP] and I have been using the following code. I am trying to upload a file, more on a 'jpg' file, since it's my first time to upload a file. With this code though, I have been encountering several errors such as the ff:
- move_uploaded_file: failed to open stream: Permission denied
- move_uploaded_file: Unable to move 'tmp_file' to 'file'

So, what am I doing wrong?

    $name = $_FILES['file']['name'];
    $tmp_name = $_FILES['file']['tmp_name'];
        if (!empty($name)) {
           $folder = 'files/';
             if (move_uploaded_file($tmp_name, $folder.'image.jpg')) {
                echo 'Uploaded';
             }
       } 

?>

<form method="post" enctype="multipart/form-data" action="untitled%20text.php">
<input type="file" name="file"/> <br/> <br/>
<input type="submit"/>
</form>

--------- Edited (December 23, 2015)

Coming from the answers, I made the conclusion that folders with permissions will produce as an "Failed to open Stream" error because the PHP code (user) has no permission to touch the file.

3 Answers3

0

try like this to change folder permission,

chmod 777 folder_path 

refer this link

Community
  • 1
  • 1
Ayyanar G
  • 1,545
  • 1
  • 11
  • 24
0

You can also...

if( !is_dir( $folder) )
{
    mkdir( $folder, 0777, TRUE );
}
Vladimir Ramik
  • 1,920
  • 2
  • 13
  • 23
0

if you work on localhost try another Drive or Dir or change Dir permission may be it is Write Protected (read only) ... if your program is online change the dir permission from file manager or use .

chmod 777 folder_path