Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

Show Pictures

Ion2
Posts: 41
Joined: Mon Jan 18, 2016 3:01 pm

Show Pictures

Unread post by Ion2 »

Hi!

My hope was to use this example: http://wiki.nubuilder.net/nubuilderv3/i ... base_table

As it did not work out. I downloaded the Sample Application provided here: https://www.nubuilder.net/sample.php

It should look like this:
https://www.nubuilder.net/screenshots.php?pic=8
https://www.nubuilder.net/screenshots.php?pic=8
STPLG.jpg (60.91 KiB) Viewed 149776 times
It looked like this:
on my XAMPP
on my XAMPP
FILEandSHOW.jpg (76.1 KiB) Viewed 149776 times
What am I doing wrong? Is the Sample Application outdated?

Testing it on my live application gives better results. I get the upload dialog. But by saving the data, I get a "Requested JSON parse failed.":
Live Application
Live Application
Application.jpg (138.92 KiB) Viewed 149776 times
I hope somebody can help!

Thx,
Timo
Ion2
Posts: 41
Joined: Mon Jan 18, 2016 3:01 pm

Re: Show Pictures

Unread post by Ion2 »

The fields have been created in my table. The Custom Code in the After Save section has been customized accordingly:

____________________________________________________________________________________
IF("#FILES#" != '#FILES'.'#'){ //has something been uploaded?

$J = json_decode("#FILES#"); //fetch the uploaded file information

$name = $J[0]->{'name'};
$type = $J[0]->{'type'};

$contents = file_get_contents(sys_get_temp_dir().$name); //obtain the contents of the file
$contents = addslashes($contents);
//put the file information and contents into the database
$s = "
UPDATE inventory
SET
inventory_file_blob = '$contents',
inventory_file_name = '$name',
inventory_file_type = '$type'
WHERE INVENTRORY_ID = '#RECORD_ID#'
";

nuRunQuery($s);

unlink(sys_get_temp_dir().$name); //delete the temporary file.

}

____________________________________________________________________________________

Also the PHP Code: SHOW I found in the Sample Application has been modified accordingly:
____________________________________________________________________________________
$s = "

SELECT *
FROM inventory
WHERE INVENTRORY_ID = '#RECORD_ID#'

";

$t = nuRunQuery($s);
$r = db_fetch_object($t);


header("Content-Type: $r->inventory_file_type");
echo $r->inventory_file_blob;


____________________________________________________________________________________

It seems that I have two issues:
  • Hitting the Save-Button gives me the message "Requested JSON parse failed." The table fields inventory_file_name and inventory_file_type get filled, but inventory_file_blob stays emty.
  • After manually uploading the BLOB via phpMyAdmin it looks like in the Sample Application on my XAMPP
like in the Sample Application
like in the Sample Application
like_Sample_Application.jpg (134.29 KiB) Viewed 149768 times
I hope to get some feedback to my two issues.

Thank you so much, it is a great application to me,
Timo
Ion2
Posts: 41
Joined: Mon Jan 18, 2016 3:01 pm

Re: Show Pictures

Unread post by Ion2 »

Hi!

It looks like a general problem. I tried to descibe it as detailed as possible, in hope to get some feedback.

I cheked:
  • write permition on tmp => okay
  • PHP Version => 5.6.15
  • post_max_size in php.ini => 8M
Please help me!
  • Why does nuBuilder fill the fields inventory_file_name and inventory_file_type, but leaves the field inventory_file_blob empty? (please see above for detailed description)
Thx, Timo
admin
Site Admin
Posts: 2778
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5

Re: Show Pictures

Unread post by admin »

Ion2,

Here's a working copy of the live demo (to show how it does it) ..
livedemo.zip
(734.68 KiB) Downloaded 1532 times
Steven
Ion2
Posts: 41
Joined: Mon Jan 18, 2016 3:01 pm

Re: Show Pictures

Unread post by Ion2 »

Dear Steven,

thank you very much for your support. I am very grateful! I uploaded the new livedemo right away to my XAMPP.

The errors remain the same as shown in the second picture of my first post:

The iFrame "uloadpic" shows: "Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\nubuilder\nucommon.php on line 1101"
The iFrame "showpic" shows: "Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\nubuilder\nucommon.php on line 1101"

I checked the Custom Code in the After Save section of the form and the PHP Code of FILE and SHOW. They seems to be identical like in the old demo.

I checked the line 1101 in nucommon.php:

Code: Select all

1093 function nuBuildHashData($J, $T){
1094
1095    $hash               = array();
1096    $ignore             = array();
1097    $ignore[]           = 'sre_layout';
1098    $ignore[]           = 'form_data';
1099    $ignore[]           = 'slp_php';
1100    
1101    foreach($J as $key => $v){                                           //-- add current hash variables
1102        
1103        if(!in_array($key, $ignore)){
1104            $hash['' . $key . '']     = $v;
1105        }
1106        
1107    }
It does not give me any hint. I hope you got the clue!

Is there something wrong with my setup?

Thank you,
Timo
ywauto
Posts: 4
Joined: Tue Jun 07, 2016 5:00 am

Re: Show Pictures

Unread post by ywauto »

I am having the same issue. imported demo project to my nuBuilder instance, the same error occurs.

Hope Steven can dig it out.
marius
Posts: 4
Joined: Wed Jun 15, 2016 2:08 pm

Re: Show Pictures

Unread post by marius »

Hello all,

It took me 2 days to find an obvious bug in the upload code. The issue was that the blob in the database was empty. That was because the file_get_contents() function was not given a proper input.
In order to solve this bug just replace in the "after save" section the line:

Code: Select all

$contents = file_get_contents(sys_get_temp_dir().$name);
with

Code: Select all

$contents = file_get_contents(sys_get_temp_dir().'/'.$name);
Good luck!
ywauto
Posts: 4
Joined: Tue Jun 07, 2016 5:00 am

Re: Show Pictures

Unread post by ywauto »

marius wrote:Hello all,

It took me 2 days to find an obvious bug in the upload code. The issue was that the blob in the database was empty. That was because the file_get_contents() function was not given a proper input.
In order to solve this bug just replace in the "after save" section the line:

Code: Select all

$contents = file_get_contents(sys_get_temp_dir().$name);
with

Code: Select all

$contents = file_get_contents(sys_get_temp_dir().'/'.$name);
Good luck!
tried the new code with no luck......
Ion2
Posts: 41
Joined: Mon Jan 18, 2016 3:01 pm

Re: Show Pictures

Unread post by Ion2 »

Great Marius!

The upload into the data base is working for me. Thank you for the new code. What is still not working is the SHOW.php

The iFrames shows the same error message after upload:

The iFrame "uloadpic" shows: "Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\nubuilder\nucommon.php on line 1101"
The iFrame "showpic" shows: "Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\nubuilder\nucommon.php on line 1101"

Thanks for the help! I hope you have an idea for the last issue.

Greetings,
Timo
marius
Posts: 4
Joined: Wed Jun 15, 2016 2:08 pm

Re: Show Pictures

Unread post by marius »

ywauto wrote:
tried the new code with no luck......
Please check in phpmyadmin if the blob that you uploaded is empty or not. The above modification should fix the update of the blob in the db.
Before the modification the file path was something like "/tmpmyfile.png". After the modification the new file path is "/tmp/myfile.png".
Post Reply