MP3 file duration PHP - php

I worked with some mp3 files, and i needed to show duration of uploaded mp3 file, I used following:
http://www.zedwood.com/article/127/php-calculate-duration-of-mp3
as told in question:
PHP Function to get MP3 duration.
But now I'm facing a problem, there are some files which are not returning any file information.
the array just contains following
Array (
[Filesize] => 16756370,
[Encoding] => Unknown
)
As the "Encoding" is Unknown its not returning any data.

I found a great PHP library, getID3(), that works for VBR files as well.
You can find it right here; it's free and is being developed actively (latest version is from from February 2013):
http://sourceforge.net/projects/getid3/files/getID3%28%29%201.x/1.9.5/

Related

GD fails to create JPG

I have an issue with GD not creating a new JPG file, it just fails. No error messages and no indication as to what is happening. This is not new code, it has been in and working for the past six years, but all of a sudden with larger images it has started failing.
As a background this is running on an old server (to be switched off and moved to a new site on PHP8 in a couple of months time) that has PHP5.3.3 with GD version 2.0.34.
The code is creating thumbnails from the high-res image (around 24-30MB) and outputting a series of thumbnails from 150px wide to 1024px wide. It fails on all. I have increased the PHP memory limit on the page to 512MB, and set the GD.JPEG_ignore_warning flag for corrupt JPGs.
But every time with these files, this line:
$src_img = #imagecreatefromjpeg($file_path);
just returns FALSE. But never falls over with an error. The file is definitely there (run the same code with a file of the same name that is <20MB and it works fine) and there is plenty of disc space/memory available for a 60MB file to be processed in memory, so I dont see that that is the issue.
A search of Google, StackOverflow and several other sites has not produced any similar issues.
Can anyone offer any thoughts as to what the issue/solution is? I have been looking at this for two days now, and we need to resolve it - simply using smaller JPG files isn't an option for this.
Thanks to #Lessmore answer above, GD was reporting an invalid JPG file, so a further search revealed this answer on StackOverflow, which solved the problem by reading the JPG from a string, rather than file:
Reading an invalid JPG with GD
Thanks all - as ever!

UPLOAD_ERR_PARTIAL with specific image from specific browser/os

I’m encountering a problem with file upload in PHP. I’m using Dropzone.js which calls a PHP script.
The PHP environment runs on Docker, and the PHP version is : 7.2.28
When I upload an image with Firefox 72 on Mac OSX, I get this in $_FILES :
Array\n(\n [file] => Array\n (\n [name] => image.png\n [type] => \n [tmp_name] => \n [error] => 3\n [size] => 0\n )\n\n)\n,
According to the documentation: error 3 means UPLOAD_ERR_PARTIAL.
The problem happens only with Firefox on Mac OSX, with PNG images with this specific size (158ko).
Other file size (even tiny or big files), other browsers, other file types, or other operating systems work fine.
The docker image runs on 3 different servers, and the problem happens on each installation.
I tried some solutions that I read on the internet, but none of them worked:
php_sapi_name() returns apache2handler
I tried to add 'Accept-Ranges: none' to my php file.
Do you have a clue on what might happen?
Thanks in advance,

Uploading .csv file from Mac - PHP

I ran into an issue earlier today with uploading a .csv file created from a Mac vs a PC through Microsoft Office Excel. Heres the issue:
We have a .csv file that contains 2 data columns. One for names and one for extensions. You take this file and upload it into our server that enables us to use it for other things. Heres the problem though, when uploading a new .csv file from a Mac, for some reason the program can't format correctly.
File Data Example:
Names | Extensions
Kevin | 109
James | 098
Uploaded from a PC and how program reads it:
Array ( [0] => Name [1] => Ext )
*This is correct because the first row is simply the names of what they contain
Uploaded from a Mac and how program reads it:
Array ( [0] => Name [1] => Ext Dave [2] => 209 Jose [3] => 140 )
Obviously there is a formatting issue between the two and I am not sure how to fix it.
Suggestions, ideas?
David
Note from the docs for fgetcsv()
If PHP is not properly recognizing the line endings when reading files either on or created by a Macintosh computer, enabling the auto_detect_line_endings run-time configuration option may help resolve the problem.
EDIT
You can enable this at runtime using
ini_set("auto_detect_line_endings", true);

Delete operation failed. (Fsys error=32, server error=1015)

I have a really weird issue with PHP, a webserver, and a media server. I have a site on a webserver that uploads an audio file to a mediaserver. The site also takes care of deleting the audio file as well. However, I'm getting a really weird error that I have Googled my brains out trying to find with no luck.
Warning: ftp_delete() [function.ftp-delete]: Delete operation failed. (Fsys error=32, server error=1015) in /......./page.php on line 175
I ran into a similar thing. This is what I did, and the issue was solved
Code:
ftp_chmod( $ftpConnection, 777, $filelist ) ;
ftp_get( $ftpConnection, $dest . '\\' . $str, $str, FTP_BINARY ) ;
ftp_delete( $ftpConnection, $str ) ;
After playing around with it some more we were able to figure out that the issue was with the media server. The delete command was coming from the web server, but if the audio file had been played very recently, the media server was keeping the audio file open for streaming and therefore any commands could not be performed on the file itself until the media server released the file. So all we had to do was wait 2 or 3 seconds and we no longer had that problem.

Streaming Uploads To PHP

I am using PHP to upload files. On the server side of the action that gets called after the upload completes is simply:
<?php
print_r($_FILES);
?>
Which outputs something like:
Array
(
[file] => Array
(
[name] => space_needlenever_lonely_alone.mp3
[type] => audio/mp3
[tmp_name] => /srv/www/uploads/php1TCIY9
[error] => 0
[size] => 3768714
)
)
The problem is I don't want to store files on the server disk ( /srv/www/uploads/php1TCIY9) at all. I actually want to store files into MongoDB using GridFS. Is there a way to stream directly into PHP without storing the file on disk on the server first? Storing files on disk requires all kinds of headaches such as permissions, and php ini configurations regarding uploads.
A websocket connection would be awesome, if I can stream the binary data directly into the server side page without writing to disk.
Or, is it possible to interact with MongoDB from a JavaScript point of view (client side) and skip interacting with PHP?
Possible, or a pipe dream?
Your PHP application is not even executed until the file upload is done. Because of this, I believe this is impossible with PHP.

Categories