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
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[]WaitFor 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 directiveregister_long_arrayswhich 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_arraysdisappear with them.Conclusion: You are learning from a very old or very bad tutorial. Find a better one.
The following is one way to upload files, there are many other ways.
As @nordenheim said,
$HTTP_POST_FILESis 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
Hope this helps.