Jump to content

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

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.