PHP.nl

move_uploaded_file

move_uploaded_file

Moves an uploaded file to a new location

bool **move_uploaded_file** string $from string $to

This function checks to ensure that the file designated by is a valid upload file (meaning that it was uploaded via PHP's HTTP POST upload mechanism). If the file is valid, it will be moved to the filename given by . from``to

This sort of check is especially important if there is any chance that anything done with uploaded files could reveal their contents to the user, or even to other users on the same system.

fromThe filename of the uploaded file.

toThe destination of the moved file.

Returns true on success.

If is not a valid upload file, then no action will occur, and will return false. from``move_uploaded_file

If is a valid upload file, but cannot be moved for some reason, no action will occur, and will return false. Additionally, a warning will be issued. from``move_uploaded_file

Voorbeeld: Uploading multiple files

<?php
$uploads_dir = '/uploads';
foreach ($_FILES["pictures"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
        $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
        // basename() may prevent filesystem traversal attacks;
        // further validation/sanitation of the filename may be appropriate
        $name = basename($_FILES["pictures"]["name"][$key]);
        move_uploaded_file($tmp_name, "$uploads_dir/$name");
    }
}
?>

Opmerking: > is

aware. However, restrictions are placed only on the
 path as to allow the moving
of uploaded files in which  may conflict
with such restrictions.  ensures
the safety of this operation by allowing only those files uploaded
through PHP to be moved.

move_uploaded_fileopen_basedirto``from``move_uploaded_file

Waarschuwing: > If the destination file already exists, it will be overwritten.

is_uploaded_file``renameHandling file uploads