Jump to content

Recommended Posts

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.

post-115475-1348240339788_thumb.jpg

Link to comment
https://forums.phpfreaks.com/topic/260636-getting-file-information/
Share on other sites

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.

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.

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.

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.