Menu Home

move_uploaded_file

osbo.com | PHP | Functions | move_uploaded_file

Moves an uploaded file to a new location

Syntax

move_uploaded_file ( string $filename , string $destination ) : bool

Parameters

filename

The filename of the uploaded file.

destination

The destination of the moved file.

Return

Returns TRUE on success. If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE. If filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file() will return FALSE. Additionally, a warning will be issued.

Examples

<?

$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");
    }
}

?>

			
			
		

PHP