ainbila Posted August 10, 2021 Share Posted August 10, 2021 i try this code to rename file when upload , the file name is rename in the folder or physical file .But in the database , it display 'array' not the name of file .How to save file name in the database ? $targetDirg= "folder/pda-semakan/gambar/"; if($_FILES['gambar']['size'] == 0 && $_FILES['gambar']['name'] == ""){ $fileNameg = $gambar; }else{ $fileNameg =explode(".",$_FILES['gambar']['name']); $newfilename= $stIC.'.'.end($fileNameg); $moveg =move_uploaded_file($_FILES["gambar"]["tmp_name"], $targetDirg.$newfilename); } Quote Link to comment https://forums.phpfreaks.com/topic/313523-rename-file-upload-in-php/ Share on other sites More sharing options...
Strider64 Posted August 10, 2021 Share Posted August 10, 2021 (edited) $file_name = $_FILES['gambar']['name']; // Original File Name: $file_size = $_FILES['gambar']['size']; $file_tmp = $_FILES['gambar']['tmp_name']; // Temporary file for the directory: $file_type = $_FILES['gambar']['type']; $file_ext = strtolower(pathinfo($_FILES['gambar']['name'], PATHINFO_EXTENSION)); /* * Set the path to the correct folder */ $dir_path = 'folder/pda-semakan/gambar/'; /* * Create unique name for file. */ $new_file_name = $dir_path . 'file-example-' . time() . '.' . $file_ext; move_uploaded_file($file_tmp, $new_file_name); I didn't test this out, but you would do something like the above. Note $new_file_name would also store the path in the database table, so if you just want the just file then just out the $dir_path after saving the file to the directory. Edited August 10, 2021 by Strider64 Quote Link to comment https://forums.phpfreaks.com/topic/313523-rename-file-upload-in-php/#findComment-1588976 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.