Jump to content

naming uploaded files


Hofmeister

Recommended Posts

I have a file uploader along with a simple HTML form and I would like to name the uploaded files in this format:

 

file_name.mp3 to (artist_name_from_POST)[song_name_from POST].mp3

 

note: literal ( ) and [ ]

 

From there I would like to use a ?str_replace? to retrieve what is in the (  ) and [  ] and create a variable from that to write an xml file so essentially it would be saving my POST data in the file names themselves. Please give any insite to how to get this done through PHP. THANKS!!

 

Dan

Link to comment
https://forums.phpfreaks.com/topic/55891-naming-uploaded-files/
Share on other sites

<?php
$tmp_name = $_FILES["file"]["tmp_name"][$key];
$dir = "where/file/will/be/saved/";  // Don't forget the trailing slash
$new_name = '('.$_POST['artist'].')['.$_POST['song_name'].']';
if(move_uploaded_file($tmp_name, $dir.$new_name)){
    rename($dir.$temp_name,$new_name);
}
?>

Link to comment
https://forums.phpfreaks.com/topic/55891-naming-uploaded-files/#findComment-276112
Share on other sites

pefect thats what i tried but I was using double quotes not literal singles...now from there I think I would have to do a preg_match to find each name seperately and then a str_replace to get rid of the [ ] or ( ) correct? I not very familar with preg_match any help there?

 

Thanks again!

 

Dan

Link to comment
https://forums.phpfreaks.com/topic/55891-naming-uploaded-files/#findComment-276118
Share on other sites

Archived

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

×
×
  • 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.