Content Disposition problem: incorrect filename | Search |
NowSMS Support Forums ⬆ WAP Technical Discussions (unsupported) ⬆ Archive through February 16, 2009 ⬆ |
◄ ► |
Author | Message | |||
Graham Macaskill New member Username: Grahamm Post Number: 1 Registered: 05-2007 |
Hi I have a problem with download filenames. Files downloaded to Samsung mobile phones using php readfile are not named properly on save. The file name ends up as something like sid=adfdggffg (this is a get parameter passed in the url) instead of pic.jpg. Any ideas on why this happens? Here's the code if (!$fdl = @fopen ($fileName,'r')){ die ("Cannot Open File!"); } else { $pathinfo = pathinfo ($fileName); $extension = $pathinfo['extension']; switch (trim (strtolower ($extension))) { case "gif": $contentType = "image/gif"; break; case "jpg": $contentType = "image/jpeg"; break; //case "jpg": $contentType = "image/jpg"; break; case "jpeg": $contentType = "image/jpeg"; break; case "bmp": $contentType = "image/bmp"; break; case "wbmp": $contentType = "image/vnd.wap.wbmp"; break; case "amr": $contentType = "audio/amr"; break; case "mid": $contentType = "audio/midi"; break; case "mp3": $contentType = "audio/mpeg3"; break; case "wav": $contentType = "audio/wav"; break; case "3gp": $contentType = "video/3gpp"; break; case "mp4": $contentType = "video/mp4"; break; case "mpg": $contentType = "video/mpeg"; break; default: $contentType = "multipart/mixed"; break; } header ("Content-type: $contentType"); header ("Content-Disposition: attachment; filename=\"" . basename ($fileName) . "\""); header ("Content-length:" . (string) (filesize ($fileName))); sleep (1); readfile ($fileName); fclose ($fdl); | |||
Bryce Norwood - NowSMS Support Board Administrator Username: Bryce Post Number: 7279 Registered: 10-2002 |
Hi, You could try adding the file name to the "Content-type:" parameter using "name=xxxxx" ... but it sounds like the browser in question just is not very smart. I'd probably take the easy way out, and when building my GET URLs, I would put the filename in the last paramter ... even though it sounds like you might end up with "parm=" as part of the name. (Maybe using "parm=/filename.ext" would get around that.) A thought for you anyway ... -bn |