Drummin Posted April 9, 2012 Share Posted April 9, 2012 Working on a music/video project. Uploaded tracks are stored in user files and product info is stored to DB. What I've been trying to figure out is getting the product information directly from the upload, much like you see in the shot attached. As I haven't had success with that, I've been trying to get the duration of a track using this code. $fp = fopen($file, 'r'); $size_in_bytes = filesize($file); fseek($fp, 20); $rawheader = fread($fp, 16); $header = unpack('vtype/vchannels/Vsamplerate/Vbytespersec/valignment/vbits', $rawheader); $tsec = number_format($size_in_bytes/$header['bytespersec'],2); $minutes = intval(($tsec / 60) % 60); $seconds = intval($tsec % 60); $sec="$minutes".":".($seconds<10 ? "0$seconds" : "$seconds"); This is working fine when file names are plain text, however it fails when when there are commas or brackets. I don't know if the code can be adjusted to work with these file names or I need to take a different approach. examples $file ="A cool track, once again"; $file ="A cool track (once again)"; As artists can be picky about their music, I don't want to rename their tracks, but really we shouldn't even have spaces in the names. I could save original name to DB and rename the file, but not sure about restoring original when it come time to download the file. In any case, I hope you understand my problem and can offer some advice. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/260636-getting-file-information/ Share on other sites More sharing options...
The Little Guy Posted April 9, 2012 Share Posted April 9, 2012 maybe you want to use: http://getid3.sourceforge.net/ Quote Link to comment https://forums.phpfreaks.com/topic/260636-getting-file-information/#findComment-1335803 Share on other sites More sharing options...
requinix Posted April 9, 2012 Share Posted April 9, 2012 As artists can be picky about their music, I don't want to rename their tracks, but really we shouldn't even have spaces in the names. I could save original name to DB and rename the file, but not sure about restoring original when it come time to download the file. In any case, I hope you understand my problem and can offer some advice. Thanks. You can rename the file on the server to whatever you want. I even recommend it. Whatever name, whatever directory. What the user will see is what you show them. As long as you store the original information (eg, filename) somewhere then you can show it to them later. For example, download scripts. The URL can be anything because the (suggested) name of the downloaded file is given by your script in the Content-Disposition header. Quote Link to comment https://forums.phpfreaks.com/topic/260636-getting-file-information/#findComment-1335820 Share on other sites More sharing options...
Psycho Posted April 9, 2012 Share Posted April 9, 2012 I agree with both of the above. Quote Link to comment https://forums.phpfreaks.com/topic/260636-getting-file-information/#findComment-1335823 Share on other sites More sharing options...
Drummin Posted April 9, 2012 Author Share Posted April 9, 2012 As artists can be picky about their music, I don't want to rename their tracks, but really we shouldn't even have spaces in the names. I could save original name to DB and rename the file, but not sure about restoring original when it come time to download the file. In any case, I hope you understand my problem and can offer some advice. Thanks. You can rename the file on the server to whatever you want. I even recommend it. Whatever name, whatever directory. What the user will see is what you show them. As long as you store the original information (eg, filename) somewhere then you can show it to them later. For example, download scripts. The URL can be anything because the (suggested) name of the downloaded file is given by your script in the Content-Disposition header. Thanks for the advice. How do I go about renaming the file back to the original when It's downloaded? And also thanks to The Little Guy for the link but I'm trying to not use any outside programs requiring a license. Quote Link to comment https://forums.phpfreaks.com/topic/260636-getting-file-information/#findComment-1335824 Share on other sites More sharing options...
Psycho Posted April 9, 2012 Share Posted April 9, 2012 As artists can be picky about their music, I don't want to rename their tracks, but really we shouldn't even have spaces in the names. I could save original name to DB and rename the file, but not sure about restoring original when it come time to download the file. In any case, I hope you understand my problem and can offer some advice. Thanks. You can rename the file on the server to whatever you want. I even recommend it. Whatever name, whatever directory. What the user will see is what you show them. As long as you store the original information (eg, filename) somewhere then you can show it to them later. For example, download scripts. The URL can be anything because the (suggested) name of the downloaded file is given by your script in the Content-Disposition header. Thanks for the advice. How do I go about renaming the file back to the original when It's downloaded? And also thanks to The Little Guy for the link but I'm trying to not use any outside programs requiring a license. Just store the original file name in your database, then look for some example download scripts - most of them should show how you can dynamically set the file name for the download. Also, the getID3() class is a free for non-commercial use. And, depending on how you implement it you can probably use it for commercial use without payment. look at the info at the bottom of the page. Quote Link to comment https://forums.phpfreaks.com/topic/260636-getting-file-information/#findComment-1335826 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.