1

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.

Community
  • 1
  • 1
Nick Coad
  • 3,623
  • 4
  • 30
  • 63
  • 2
    What makes you think it is corrupted? – PeeHaa Oct 08 '14 at 00:15
  • 2
    Have you compared the file hashes, or file size — what's the difference? – l'L'l Oct 08 '14 at 00:16
  • 5
    'Access Denied' is not the same as 'corrupted'. The files will be written by the web server using whatever access and user it has been granted. Do you actually have access to those files when you're trying to open them? –  Oct 08 '14 at 00:16
  • 1
    What are your `upload_max_filesize` & `max_post_size` values? – Darren Oct 08 '14 at 00:16
  • 3
    Run notepad++ as administrator and then attempt to open the files that you uploaded. – Scopey Oct 08 '14 at 00:18
  • 1
    have you checked your error logs? do you see "success" after you hit "submit"? – danyamachine Oct 08 '14 at 00:21
  • I've updated the question with some responses. I've indicated in the question that another question would help me fix the problem, but now I've realised that I think I need to change the user that PHP runs under so it's not creating Administrator only files. I have no idea how to do this, but I'll have a look around. – Nick Coad Oct 08 '14 at 00:36

1 Answers1

-1

Check your system proxies and vpn

Maybe you are using a proxy that is corrupt your file with bad chunks

I lost a day to find this solution for my similar problem

If you are using MacOS and SSHProxy, disable it and remove proxy settings from your web browser

YiiMan
  • 11
  • 1