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.