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 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); } ?> 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 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"; ?> Link to comment https://forums.phpfreaks.com/topic/55891-naming-uploaded-files/#findComment-276122 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.