Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
Replace Stored File Topic is solved
-
- Posts: 149
- Joined: Mon Dec 05, 2011 12:23 pm
- Location: Newton Abbot, UK
- Has thanked: 1 time
- Been thanked: 1 time
Replace Stored File
How can I update the sfi_json column in zzzzsys_file? Really, I'm looking for the method used to encode the object into JSON.
-
- nuBuilder Team
- Posts: 4299
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 445 times
- Contact:
Re: Replace Stored File
Depending on where the object or file is stored, this might help: viewtopic.php?p=24423
-
- Posts: 149
- Joined: Mon Dec 05, 2011 12:23 pm
- Location: Newton Abbot, UK
- Has thanked: 1 time
- Been thanked: 1 time
Re: Replace Stored File
Using this code:
I get a value that will go into the database but doesn't work (i.e no image is shown). The JSON encoded string is nothing like the one that gets stored when I use the standard "Stored Files " form. For a start it has alot of "/" (all escaped) and "+" characters which are not in the "correct" encoding - I will have to do some searching to discover what's going on (I guess some modified encoding) , unless you have a quick answer?
Code: Select all
$image = file_get_contents($target_file);
$filesize = filesize($target_file);
$arr = array("file"=>base64_encode($image), "name"=>basename($target_file), "size"=>$filesize, "type"=>"image/png");
$json = json_encode($arr);
-
- Posts: 149
- Joined: Mon Dec 05, 2011 12:23 pm
- Location: Newton Abbot, UK
- Has thanked: 1 time
- Been thanked: 1 time
Re: Replace Stored File
OK, cracked it. I use nuBuilder "Stored Files" to do the upload, then copy the encoded "file" string from sfi_json, and see that it is encoded using the data URI scheme https://en.wikipedia.org/wiki/Data_URI_scheme
I can now update sfi_json with my JSON encoded variable.
Code: Select all
$image = file_get_contents($target_file);
$filesize = filesize($target_file);
$image64=base64_encode($image);
$arr = array("file"=>base64_encode('data:image/png;base64,' . $image64), "name"=>basename($target_file), "size"=>$filesize, "type"=>"image/png");
$json = json_encode($arr);