Jump to content

Setting a Name


perezf

Recommended Posts

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>

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

[!--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 happen

for instance instead of it being picture.jpg its only picture
Link to comment
Share on other sites

[!--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 happen

for 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]

Link to comment
Share on other sites

[!--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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.