We now have a youtube channel. Subscribe!

PHP | move_uploaded_file() Function

PHP move_uploaded_file() Function


Hello folks! welcome back to a new edition of our tutorial on PHP. In this tutorial guide, we are going to be studying about the PHP move_uploaded_file() Function.

The built-in move_uploaded_file() function moves an uploaded file to a new location.

Syntax

Following below is the syntax to use this function -

bool move_uploaded_file ( string $filename , string $destination )


This built-in PHP function checks to ensure that the file designated by the filename is a valid uploaded file, which means that it has uploaded through PHP HTTP POST upload mechanism. If the file is valid then, it can be moved to filename given by the destination.

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

Return Value

If the filename is not a valid uploaded file, no action is taken and it returns false. If the filename is a valid uploaded file but can not be moved for some reasons, then no action occurs and it returns false. Additionally, a warning can be issued.

Example

Try out the below example -

<?php
   $uploads_dir = "/PhpProject/uploads";
   foreach($_FILES["pictures"]["error"] as $key => $error) {
      if($error == UPLOAD_ERR_OK) {
         $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
         $name = basename($_FILES["pictures"]["name"][$key]);
         move_uploaded_file($tmp_name, "$uploads_dir/$name");
      }
   }
?>


Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we are going to be discussing about the PHP parse_ini_file() Function.

Do feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain