Hofmeister Posted June 17, 2007 Share Posted June 17, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/55891-naming-uploaded-files/ Share on other sites More sharing options...
The Little Guy Posted June 17, 2007 Share Posted June 17, 2007 <?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); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/55891-naming-uploaded-files/#findComment-276112 Share on other sites More sharing options...
Hofmeister Posted June 17, 2007 Author Share Posted June 17, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/55891-naming-uploaded-files/#findComment-276118 Share on other sites More sharing options...
The Little Guy Posted June 17, 2007 Share Posted June 17, 2007 <?php list($artist, $song) = explode(")[",$filename); $artist = rtrim($artist, "("); $song = ltrim($song, "]"); echo "Artist: $artist"; echo "Song: $song"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/55891-naming-uploaded-files/#findComment-276122 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.