Re: Aw: Re: [PHP-WIN] Storing binary data in mySQL
[email protected] (Jacob Kruger) Thu, 27 Oct 2016 02:40:45 +0200
| Newsgroups | php.windows |
|---|---|
| Message-ID | <[email protected]> |
Next question then - how did you read the file's contents into a variable before encoding it? Ask since, base64_encode requires a string parameter, and, if I read the files in using fopen($s_file_name, "rb"), then it returns a resource, whereas if I use file_get_contents, to read the audio clips contents in as a string, and then encode them, they still get decoded as a corrupted version, most likely due to reading in binary data the wrong way? TIA Jacob Kruger Blind Biker Skype: BlindZA "Resistance is futile, but, acceptance is versatile..." On 2016-10-26 11:31 AM, Sascha Meyer wrote: > Hi Jacob, > > I had a lot of problems storing files properly inside databases (mainly with MSSQL rather than MySQL), I ended up using base64_encode() (http://php.net/manual/de/function.base64-encode.php) before saving the file and than re-decoding the files with base64_decode on download. If combined with proper MIME type detection (stored alongside with the base64-encoded content, there were no problems with various file types. > > Just my idea, perhaps it'll help. > > Good luck! > > Best, Sascha > >> Gesendet: Mittwoch, 26. Oktober 2016 um 10:42 Uhr >> Von: "Jacob Kruger" <[email protected]> >> An: "[email protected]" <[email protected]> >> Betreff: Re: [PHP-WIN] Storing binary data in mySQL >> >> Ok, the primary issue seems to be with just one file type - .wav - I >> rewrote the code a bit, working with just PDO, making sure it was all >> doing what I wanted it to do, and it works fine with .mp3 and .ogg audio >> clips, but, .wav still gets corrupted, so my guess would be that some >> form of encoding, or something is causing hassles - this database is set >> to use inno DB and UTF-8, but anyway. >> >> >> Either way, for now, will just limit audio clips to those two file >> formats, and take it from there. >> >> >> Stay well >> >> >> Jacob Kruger >> Blind Biker >> Skype: BlindZA >> "Resistance is futile, but, acceptance is versatile..." >> >> On 2016-10-25 9:58 AM, Jacob Kruger wrote: >>> I have a minor issue with storing specific types of data in a blob >>> field in mySQL. >>> >>> >>> I am working with PDO, and while it seems to work alright with image >>> files, etc., if I try to store a sound clip in the database, using >>> exact same code, etc., when I then pull the data out of the database >>> again, setting content-disposition, file name, content-type, etc. back >>> to match the original values, the audio clips seem to get corrupted >>> when being extracted? >>> >>> >>> Any thoughts on what I need to bear in mind/try while extracting, or >>> storing the data? >>> >>> >>> Can also post the code here, but, thought would first just ask, since >>> when I do the exact same thing with image files, they seem fine when >>> they then get extracted/rendered. >>> >>> >>> Suppose should also try some other file types, like documents, PDF >>> files, etc., just to test, but, just find it a bit odd that one type >>> of file - .jpg, .gif, or .png - works fine, but, others, like .wav, >>> .mp3 and .ogg don't want to cooperate. >>> >>> >>> TIA >>> >>> >>> Jacob Kruger >>> Blind Biker >>> Skype: BlindZA >>> "Resistance is futile, but, acceptance is versatile..." >>> >>> >> >> -- >> PHP Windows Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> >