Show Pictures

Show Pictures

Postby Ion2 » Thu May 26, 2016 2:35 am

Hi!

My hope was to use this example: http://wiki.nubuilder.net/nubuilderv3/index.php/Miscellaneous#Uploading_a_file_to_a_database_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:
STPLG.jpg
https://www.nubuilder.net/screenshots.php?pic=8
STPLG.jpg (60.91 KiB) Viewed 9927 times

It looked like this:
FILEandSHOW.jpg
on my XAMPP
FILEandSHOW.jpg (76.1 KiB) Viewed 9927 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.":
Application.jpg
Live Application
Application.jpg (138.92 KiB) Viewed 9927 times

I hope somebody can help!

Thx,
Timo
Ion2
 
Posts: 41
Joined: Mon Jan 18, 2016 11:31 pm

Re: Show Pictures

Postby Ion2 » Thu May 26, 2016 5:43 pm

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_Sample_Application.jpg
like in the Sample Application
like_Sample_Application.jpg (134.29 KiB) Viewed 9919 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 11:31 pm

Re: Show Pictures

Postby Ion2 » Mon May 30, 2016 6:43 pm

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
Ion2
 
Posts: 41
Joined: Mon Jan 18, 2016 11:31 pm

Re: Show Pictures

Postby admin » Wed Jun 08, 2016 11:30 am

Ion2,

Here's a working copy of the live demo (to show how it does it) ..

livedemo.zip
(734.68 KiB) Downloaded 202 times


Steven
admin
Site Admin
 
Posts: 3123
Joined: Mon Jun 15, 2009 9:53 am

Re: Show Pictures

Postby Ion2 » Wed Jun 08, 2016 4:19 pm

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
Ion2
 
Posts: 41
Joined: Mon Jan 18, 2016 11:31 pm

Re: Show Pictures

Postby ywauto » Wed Jun 08, 2016 4:39 pm

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

Hope Steven can dig it out.
ywauto
 
Posts: 4
Joined: Tue Jun 07, 2016 12:30 pm

Re: Show Pictures

Postby marius » Wed Jun 15, 2016 9:44 pm

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!
marius
 
Posts: 4
Joined: Wed Jun 15, 2016 9:38 pm

Re: Show Pictures

Postby ywauto » Wed Jun 15, 2016 11:37 pm

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......
ywauto
 
Posts: 4
Joined: Tue Jun 07, 2016 12:30 pm

Re: Show Pictures

Postby Ion2 » Wed Jun 15, 2016 11:48 pm

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
Ion2
 
Posts: 41
Joined: Mon Jan 18, 2016 11:31 pm

Re: Show Pictures

Postby marius » Wed Jun 15, 2016 11:50 pm

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".
marius
 
Posts: 4
Joined: Wed Jun 15, 2016 9:38 pm

Next

Return to General