PHP implements file upload function
P粉868586032
P粉868586032 2024-03-25 18:04:14
0
2
553

I want to upload a file to a given folder.

<?php
$folder = "upload/";
if (is_uploaded_file($HTTP_POST_FILES['filename']['tmp_name']))  {   
    if (move_uploaded_file($HTTP_POST_FILES['filename']['tmp_name'], $folder.$HTTP_POST_FILES['filename']['name'])) {
         echo "File uploaded";
    } else {
         echo "File not moved to destination folder. Check permissions";
    };
} else {s
     echo "File is not uploaded";
}; 
?>

The error is:

Note: Undefined variable: HTTP_POST_FILES in C:\wamp\www\sdg\import\ips.php on line 3

P粉868586032
P粉868586032

reply all(2)
P粉464082061

PHP 4.1 introduces Super global. They replace the old long named arrays that contained the data extracted from the request. $_FILES[] Replaced $HTTP_POST_FILES[], $_GET[ ] Replaced $HTTP_GET_VARS[] Wait

For subsequent PHP 4 versions, old arrays and new arrays can be used side by side. PHP 5 disables the generation of old arrays by default and introduces the php.ini directive register_long_arrays which can be used to re-enable old arrays create.

As of PHP 5.4, the old long named arrays are completely removed and register_long_arrays disappear with them.

Conclusion: You are learning from a very old or very bad tutorial. Find a better one.

P粉788571316

The following is one way to upload files, there are many other ways.

As @nordenheim said, $HTTP_POST_FILES is deprecated as of PHP 4.1.0, so its use is not recommended.

PHP code (upload.php)

 5000000) {
        $msg = "Sorry, your file is too large.";
    } elseif (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
        $msg = "The file " . basename($_FILES["fileToUpload"]["name"]) . " has been uploaded.";
    }
}

?>

HTML code to activate the function


Select file to upload:

Hope this helps.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template