Page 1 of 1

Problem inserting an uploaded file into database

Posted: Thu Sep 25, 2003 2:08 pm
by nirma78
Hi

I am trying to insert an uploaded file into the database.

I found that it can be done with a query as below :
insert into tablename(blobfield) values(load_file('/path/to/file.txt'))

I am running the code from windows machine which uses unix server.
when I try to give in something like :

Code: Select all

<?php
$main_query = "INSERT INTO submitted_material_list
                       (Application_Material_ID,
                        Application_ID,
                        Physical_Copy,
                        Rec_By,
                        Rec_Date)
                VALUES ($app_mat_id,
                        $app_id,
                        load_file('check/$_FILES['userfile']['name']'),
                        $app_id,
                        SYSDATE)";
?>
It gives me syntax / parse error on load_file()
Can anyone please help me out with this !!

Thanks in advance

Posted: Fri Sep 26, 2003 10:22 pm
by nigma
Maybe

Code: Select all

<?php
$main_query = "INSERT INTO submitted_material_list 
                       (Application_Material_ID, 
                        Application_ID, 
                        Physical_Copy, 
                        Rec_By, 
                        Rec_Date) 
                VALUES ($app_mat_id, 
                        $app_id, 
                        load_file("check/$_FILES&#1111;'userfile']&#1111;'name']"), 
                        $app_id, 
                        SYSDATE)"; 
?>
If that doesn't work please let me know.

Posted: Mon Sep 29, 2003 3:34 am
by twigletmac
The problem is that array within the double quotes, for example,

Code: Select all

$string = "blah $array['element'] blah";
will give a parse error, whereas

Code: Select all

$string = "blah {$array['element']} blah";
or

Code: Select all

$string = "blah $array[element] blah";
won't.

Mac

Posted: Mon Sep 29, 2003 8:44 am
by devork
why don't you upload the files to secure directory and store their paths in database ?

Posted: Mon Sep 29, 2003 11:03 pm
by nigma
Hey twig, thanks for saving my ass on that one, I shouldn't have answered the question if I wasn't 100% sure of my answer.

Posted: Wed Oct 01, 2003 5:00 am
by devork
nigma ?

Posted: Wed Oct 01, 2003 9:54 am
by nirma78
hey guys thanks for your reply !!

I tried doing

Code: Select all

<?php
$main_query = "INSERT INTO submitted_material_list
                       (Application_Material_ID,
                        Application_ID,
                        Physical_Copy,
                        Rec_By,
                        Rec_Date)
                VALUES (1,
                        $app_id,
                        load_file("check/{$_FILES['userfile']['name']}"),
                        $app_id,
                        SYSDATE)";
?>
$result = $db->Execute($main_query) or die($db->ErrorMsg());

I tried :

Code: Select all

<?php
load_file("check/$_FILES['userfile']['name']")

load_file("check/$_FILES[userfile][name]}")

load_file("check/{$_FILES['userfile']['name']}")
?>
BUT IT STILL GIVES ME ERROR - PARSE ERROR on load_file()

PLEASE HELP ....
Thanks in advance

Posted: Thu Oct 02, 2003 6:03 am
by twigletmac
You need to change:

Code: Select all

"check/{$_FILES['userfile']['name']}"
to

Code: Select all

'check/{$_FILES['userfile']['name']}'
it's the double quotes within double quotes causing the problem.

Mac

Posted: Thu Oct 02, 2003 8:35 am
by nirma78
Thanks for the reply.

I changed my code as :

Code: Select all

<?php
load_file('check/{$_FILES['userfile']['name']}')
?>
so now the error has changed. It gives me the below error :

ORA-00904: "LOAD_FILE": invalid identifier

So does this mean that LOAD_FILE is not supported in Oracle ??

Please help.

Thanks in advance

Posted: Thu Oct 02, 2003 8:38 am
by nirma78
I am running it from windows machine, having a unix server and Oracle 9i is the database...

Sorry if I didnt mention it earlier, I didnt know that this will affect my question anywhere..

So if LOAD_FILE is not supported in Oracle, how can I get it done ?? Is there a way to do it or not ??

Thanks