Jump to content

Archived

This topic is now archived and is closed to further replies.

perezf

Setting a Name

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>

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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]

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.