I have a pretty simple upload script I'm playing around with in a localhost dev environment. The form takes a file and posts it to a receiving script which saves the file. Basically your stock-standard PHP file upload form.
uploader.php
<!doctype html>
<html>
<head>
<title>File upload test</title>
</head>
<body>
<form action="upload_receiver.php" method="POST" enctype="multipart/form-data">
<input name="upload_file" type="file"/>
<input name="upload_submit" type="submit"/>
</form>
<script>
</script>
</body>
</html>
upload_receiver.php
<?php
$upload_dir = "uploads/";
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if (move_uploaded_file($_FILES['upload_file']['tmp_name'], $upload_dir . basename($_FILES['upload_file']['name'])))
{
echo 'success';
}
}
The problem is, every single file I attempt to 'upload' is arriving in my 'uploads' folder seem as though they may be in a corrupted state and will no longer open. I can't even open them in Notepad++ to view the contents of the files, Notepad++ throws an error: "Access is denied."
Has anyone encountered this before? Any ideas why this might be happening, and how I can correct it?
- Operating System: Windows
- Web Server: Apache
- PHP Version: PHP 5.5.6
Edit to clarify some questions raised in comments:
I'm guessing that the files are corrupted because I have full access to the folder they are being uploaded to, and I can see the files there, but if I click on an image for example, I can't see the preview thumbnail.
It's true that the problem may not be corruption, I've rephrased the question to say that they seem to be corrupted.
I do see "success" after the submit, and there are no errors in the Apache logs.
max_upload_size
is 500M. post_max_size
is 500M.
Edited again:
After comparing MD5 hashes as helpfully suggested by I'L'I, I've determined that the files are fine (they're not corrupted). It's an access problem. I will be able to fix this using this question: Change permissions of file uploaded by PHP
Thank you to all the commenters who helped with this.