perezf Posted May 26, 2006 Share Posted May 26, 2006 Hey everyone,I need a way that a user could name the file he would be uploadingin the form i made it has it where he can browse for the fileselect what folder to upload tobut i also wanted to add a textbox where the user could name the file.I made a textbox and gave it the name "rename"if anyone could help me accomplish this i would greatly appreciate itheres the php script to upload <?php$location = $_POST['options'];move_uploaded_file ($_FILES['img1'] ['tmp_name'], "photos/$location/ {$_FILES['img1'] ['name']}")?><p>You Sent: <?php echo $_FILES['img1'] ['name']; ?></p> Quote Link to comment https://forums.phpfreaks.com/topic/10476-setting-a-name/ Share on other sites More sharing options...
KrisNz Posted May 26, 2006 Share Posted May 26, 2006 Just change $_FILES['img1'] ['name'] to $_POST['rename'].But you should also check that they've provided a valid filename and that they aren't going to either intentionally or unintentionally write over another file. Quote Link to comment https://forums.phpfreaks.com/topic/10476-setting-a-name/#findComment-39087 Share on other sites More sharing options...
perezf Posted May 26, 2006 Author Share Posted May 26, 2006 [!--quoteo(post=377203:date=May 25 2006, 11:22 PM:name=KrisNz)--][div class=\'quotetop\']QUOTE(KrisNz @ May 25 2006, 11:22 PM) [snapback]377203[/snapback][/div][div class=\'quotemain\'][!--quotec--]Just change $_FILES['img1'] ['name'] to $_POST['rename'].But you should also check that they've provided a valid filename and that they aren't going to either intentionally or unintentionally write over another file.[/quote]how would i do that????Now it changes it to the name the user types but it wont place the extension after how can i make this happenfor instance instead of it being picture.jpg its only picture Quote Link to comment https://forums.phpfreaks.com/topic/10476-setting-a-name/#findComment-39088 Share on other sites More sharing options...
KrisNz Posted May 26, 2006 Share Posted May 26, 2006 [!--quoteo(post=377204:date=May 26 2006, 01:30 PM:name=perezf)--][div class=\'quotetop\']QUOTE(perezf @ May 26 2006, 01:30 PM) [snapback]377204[/snapback][/div][div class=\'quotemain\'][!--quotec--]how would i do that????Now it changes it to the name the user types but it wont place the extension after how can i make this happenfor instance instead of it being picture.jpg its only picture[/quote][code]$ext = explode(".",$_FILES['img1'] ['name']);$ext = array_pop($ext);$newFileName = $_POST['rename'].".".$ext;[/code]as for checking if a file exists[a href=\"http://au2.php.net/file_exists\" target=\"_blank\"]file_exists[/a] Quote Link to comment https://forums.phpfreaks.com/topic/10476-setting-a-name/#findComment-39090 Share on other sites More sharing options...
perezf Posted May 26, 2006 Author Share Posted May 26, 2006 [!--quoteo(post=377206:date=May 25 2006, 11:37 PM:name=KrisNz)--][div class=\'quotetop\']QUOTE(KrisNz @ May 25 2006, 11:37 PM) [snapback]377206[/snapback][/div][div class=\'quotemain\'][!--quotec--][code]$ext = explode(".",$_FILES['img1'] ['name']);$ext = array_pop($ext);$newFileName = $_POST['rename'].".".$ext;[/code]as for checking if a file exists[a href=\"http://au2.php.net/file_exists\" target=\"_blank\"]file_exists[/a][/quote]Thank you so much Quote Link to comment https://forums.phpfreaks.com/topic/10476-setting-a-name/#findComment-39093 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.