symfony: guessExtension() return the wrong mp3 file extension
i have this code, which i use in laravel 4 to upload and validate a file ( and they assure to me that this is related to Symfony HttpFoundation https://github.com/laravel/framework/issues/1968#issuecomment-21720088 )
<?php
class HomeController extends BaseController {
public function getIndex()
{
return View::make('hello');
}
public function postAddFile(){
$file = Input::file('pod');
$files = array('file'=>Input::file('pod') );
$rules = array('file'=>'required|mimes:mp3');
echo 'File : '.$file->getClientOriginalName().'<br />';
echo 'Mime : '. $file->getMimeType().'<br />';
echo 'Ext : '. $file->guessExtension().'<br />';
$validate = Validator::make($files,$rules);
if($validate->passes()){
echo 'Mime : '. $file->getMimeType().'<br />';
}else{
var_dump($validate->messages());
}
$file->move(storage_path().'/cache', $file->getClientOriginalName());
}
}
which am use to validate the file which am uploading … but sadly the result is this :
File : test.mp3
Mime : audio/mpeg
Ext : mpga
object(Illuminate\Support\MessageBag)#151 (2) { ["messages":protected]=> array(1) { ["file"]=> array(1) { [0]=> string(37) "The file must be a file of type: mp3." } } ["format":protected]=> string(8) ":message" }
as every one see the validation failed to read the extension of the file, and the result of the $file->guessExtension() is mpga mean while it should be mp3 …
so am not so sure what is the problem here, and if this is something related to php configuration … my server is ubuntu with php 5.3
About this issue
- Original URL
- State: closed
- Created 11 years ago
- Reactions: 1
- Comments: 16 (4 by maintainers)
Still a problem, mpga does not work.
@linuxjuggler yeah, and the main extension for the
audio/mpegmime type in the Apache list ismpga, notmp3. So if this is the actual logic they use, you need to usempgato allow theaudio/mpegmime type, notmp3Hi, i have been trying to fix this for a while now. Using mpga does not work. I am working with laravel 5.2. mpeg, mp3 etc. all these does not work. Any help pls?
try it for mp3: ‘sound’ => ‘file|mimetypes:application/octet-stream’,