Php move uploaded file
Contents |
PHP function move_uploaded_file
This function uploads and moves a file to a specific directory.
Syntax move_uploaded_file
- tmp is a file name of the uploaded file
- path_dest is a destination path to store the file.
move_uploaded_file(tmp, path_dest);
Note
Returns TRUE on success.
Example 1
form.html
<!DOCTYPE html> <html> <head> <title>move_uploade_file</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <form action="upload.php" enctype="multipart/form-data" name="uploadform" method="post" > <input type="file" name="image123" id="image123"/> <input type="submit" name="upload"/> </form> </body> </html>
upload.php
<?php if (isset($_POST['upload'])) { $filename = $_FILES['image123']['name']; $tmpName = $_FILES['image123']['tmp_name']; $storepath = "C:\\upload\\" . $filename; $result = move_uploaded_file($tmpName, $storepath); if (!$result) { echo "Error uploading image file"; } if (is_uploaded_file($tmpName)) { echo "File " . $tmpName . " uploaded successfully.\n"; echo "Displaying contents\n"; readfile($tmpName); } else { echo "Possible file upload attack: "; echo "filename '" . $tmpName . "'."; } } ?>
Related Links
basename-- chgrp-- chmod-- chown-- clearstatcache-- copy-- delete-- dirname-- disk_free_space-- disk_total_space-- diskfreespace-- fclose-- feof-- fflush-- fgetc-- fgetcsv-- fgets-- fgetss-- file_exists-- file_get_contents-- file_put_contents- file-- fileatime-- filectime-- filegroup-- fileinode-- filemtime-- fileowner-- fileperms-- filesize-- filetype-- flock-- fnmatch-- fopen-- fpassthru-- fputcsv-- fputs-- fread-- fscanf-- fseek-- fstat-- ftell-- ftruncate-- fwrite-- glob-- is_dir-- is_executable-- is_file-- is_link-- is_readable-- is_uploaded_file-- is_writable-- is_writeable-- lchgrp-- lchown-- link-- linkinfo-- lstat-- mkdir-- move_uploaded_file-- parse_ini_file-- parse_ini_string-- pathinfo-- pclose-- popen-- readfile-- readlink-- realpath_cache_get-- realpath_cache_size-- realpath-- rename-- rewind-- rmdir-- set_file_buffer-- stat-- symlink-- tempnam-- tmpfile-- touch-- umask-- unlink--