Jump to content


Photo

Setting a Name


  • Please log in to reply
4 replies to this topic

#1 perezf

perezf
  • Members
  • PipPipPip
  • Advanced Member
  • 301 posts
  • LocationFort Lauderdale

Posted 26 May 2006 - 02:59 AM

Hey everyone,

I need a way that a user could name the file he would be uploading

in the form i made it has it where he can browse for the file
select what folder to upload to
but 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 it

heres 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>



#2 KrisNz

KrisNz
  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts
  • LocationAuckland, New Zealand

Posted 26 May 2006 - 03:22 AM

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.

#3 perezf

perezf
  • Members
  • PipPipPip
  • Advanced Member
  • 301 posts
  • LocationFort Lauderdale

Posted 26 May 2006 - 03:30 AM

[!--quoteo(post=377203:date=May 25 2006, 11:22 PM:name=KrisNz)--][div class=\'quotetop\']QUOTE(KrisNz @ May 25 2006, 11:22 PM) View Post[/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 happen

for instance instead of it being picture.jpg its only picture

#4 KrisNz

KrisNz
  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts
  • LocationAuckland, New Zealand

Posted 26 May 2006 - 03:37 AM

[!--quoteo(post=377204:date=May 26 2006, 01:30 PM:name=perezf)--][div class=\'quotetop\']QUOTE(perezf @ May 26 2006, 01:30 PM) View Post[/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 happen

for instance instead of it being picture.jpg its only picture
[/quote]
$ext = explode(".",$_FILES['img1'] ['name']);
$ext = array_pop($ext);

$newFileName = $_POST['rename'].".".$ext;




as for checking if a file exists
[a href=\"http://au2.php.net/file_exists\" target=\"_blank\"]file_exists[/a]



#5 perezf

perezf
  • Members
  • PipPipPip
  • Advanced Member
  • 301 posts
  • LocationFort Lauderdale

Posted 26 May 2006 - 03:57 AM

[!--quoteo(post=377206:date=May 25 2006, 11:37 PM:name=KrisNz)--][div class=\'quotetop\']QUOTE(KrisNz @ May 25 2006, 11:37 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
$ext = explode(".",$_FILES['img1'] ['name']);
$ext = array_pop($ext);

$newFileName = $_POST['rename'].".".$ext;

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users