Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP upload File not saving into upload folder

Tags:

html

php

Editted

Now I am encountered another problem which is upload file is not saving into upload folder I set up.

Below are resolved

I have been working with this simple HTML and PHP code to upload files into web server but this error is keep displaying every time I tried to upload file into the server. File is not uploaded into server.

I am using Windows 7, IIS 7.5, PHP 5.6.2

I have already created folder for uploaded files (uploads) and I have given full control permission to all of my web server folders to IIS user.

I tried to search on the web first but I could not notice any similar problems as mine.

Here is detailed error message

HTTP Error 404.0 - Not Found The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

Here is my HTML script

<!DOCTYPE html>    
    <body>
        <form action="upload.php" 
              method="post" 
              enctype="multipart/form-data">
            <label for="file">
                Filename:
            </label>
            <input type="file" 
                   name="file" 
                   id="file"><br />
            <input type="submit" 
                   value="submit">
        </form>
    </body>
</html>

Here is my PHP script

<?php
    $my_folder = "uploads/";
    copy($_FILES["file"]["tmp_name"],$my_folder.$_FILES["file"]["name"]);
    echo "File uploaded.";
?>
like image 564
koreanfob Avatar asked Sep 06 '25 03:09

koreanfob


1 Answers

<?php

$my_folder = "./uploads/";

if (move_uploaded_file($_FILES['file']['tmp_name'], $my_folder . $_FILES['file']['name'])) {
    echo 'Received file' . $_FILES['file']['name'] . ' with size ' . $_FILES['file']['size'];
} else {
    echo 'Upload failed!';

    var_dump($_FILES['file']['error']);
}

Check for read/write permissions on the target folder.

PHP Manual:

  • move_uploaded_file
  • Handling of File Uploads, especially File Upload Errors
like image 128
Jens A. Koch Avatar answered Sep 07 '25 22:09

Jens A. Koch