Question regarding uploading files to database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
nirma78
Forum Commoner
Posts: 42
Joined: Wed Sep 17, 2003 2:02 pm

Question regarding uploading files to database

Post by nirma78 »

Hi !!

I need to upload a pdf file from php to oracle database.

I found that I can do this using a query as :

"insert into tablename(blobfield) values (load_file('/../../filename.pdf'))"

What I didnt understand is how do I get the path for the file which I am trying to upload. I have a form which gets the filename to be uploaded and then on clicking "upload" it calls the php program which will actually upload it into the database.

I am aware of the functions $_FILES['userfile']['name']['size'] ... but I am not able to get the path of the file to be uploaded.

How can I get the path for it ?? I am STUCK coz of this.

PLEASE HELP !!

Thanks in advance
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

Read more carefully about how to recieve uploaded files, and you'll get it.
http://se2.php.net/manual/en/features.f ... ost-method
$_FILES['userfile']['tmp_name']

The temporary filename of the file in which the uploaded file was stored on the server.
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

Hint:
Read the first comment at the page I gave you above:

heivio at hotmail dot com
09-Sep-2003 06:37

That example goes for mysql, but you'll get it.
nirma78
Forum Commoner
Posts: 42
Joined: Wed Sep 17, 2003 2:02 pm

Post by nirma78 »

Thanks a lot for your help.

Does it have a specific pre defined location where it stores it on the server ??

Thanks once again !!
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

From the very same manual page:
PHP Manual wrote: Files will by default be stored in the server's default temporary directory, unless another location has been given with the upload_tmp_dir directive in php.ini. The server's default directory can be changed by setting the environment variable TMPDIR in the environment in which PHP runs. Setting it using putenv() from within a PHP script will not work. This environment variable can also be used to make sure that other operations are working on uploaded files, as well.
nirma78
Forum Commoner
Posts: 42
Joined: Wed Sep 17, 2003 2:02 pm

Post by nirma78 »

Thanks for your reply !!

well here is my code. I am trying to move the file from the temp location
to the location I want , but it gives me the following messages :


"
Warning: move_uploaded_file(home irvali\files): failed to open stream: Read-only file system in /xxxx/xxxx/xxx/xxxx.php on line 29

Warning: move_uploaded_file(): Unable to move '/tmp/phptR0lWI' to 'home irvali\files' in /xxxx/xxxx/xxxx/xxxx.php on line 29
"
PLEASE HELP !!

Thanks a lot once again


/**********************************************************/
<?php

include_once("header.inc.php");
include_once("config.php");
include_once("adodb/adodb.inc.php");

$transcript = $_FILES['userfile']['name'][0];
$tmp_dest = $_FILES['userfile']['tmp_name'][0];
?>

<p><?php echo "transcript value : $transcript";?> </p>
<p><?php echo "temporary destination value : $tmp_dest"; ?> </p>

<?php

$dest = "xxxx\xxxx\xxxx";
$up = move_uploaded_file($_FILES['userfile']['tmp_name'][0], $dest);

if($up)
{
echo "File uploaded";
}
else
{
echo "Not uploaded";
}
?>
/*********************************************************/
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

I assume you are using windows?

It seems like you are storing it inside your home directory.

Does the Web server run as a user that has permission to write in that directory?
nirma78
Forum Commoner
Posts: 42
Joined: Wed Sep 17, 2003 2:02 pm

Post by nirma78 »

hey !!

I am on windows

If I try to put it on my C:\, then also it gives me the same error !

about the Web server run as a user has permission to write in that directory? , will have to find out...


Thanks a lot for your help
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

When PHP is on windows, you can still delimit path components with a / .

IE:
C:/winnt/notepad.exe
instead of
c:\winnt\notepad.exe

But hey!
I saw now that you might fool yourself with the backslash.
it should probably be:

$dest = "xxxx\\xxxx\\xxxx";

since backslashes have to be escaped with one backslash in a PHP string.

Please read: http://se2.php.net/types.string

But still, you can use a forward slash / instead for portabilityreasons.

One more thing:
I never did a lot of PHP on Windows, but I remember that at least when using PWS/IIS for your web server one cannot write files to d: if IIS runs on c:.

if all you want to do is to access c:, you can use a unix type path and that work work just like if c:\ was /. Then, your script would be portable to unix as well.

IE:
c:\windows\notepad.exe = /windows/notepad.exe

(Correct me if I am wrong)

All I am saying here comes out of vague memories. I am not competely sure that I am saying the truth.

Let's do it this way, if you want to:
You test these things and post a report here, to clarify what was working and what wasn't.
It is sort of good practise to post the solution to the public as well as the problem.
nirma78
Forum Commoner
Posts: 42
Joined: Wed Sep 17, 2003 2:02 pm

Post by nirma78 »

hey !!

I tried putting a \\ for the path but it still doesnt work.

So other than that do you see anything wrong in my code ?? I am not sure why is it not working for me ??

I am working on windows
the php server and oracle are running on the server machine

also does it have to do anything with the following things :

1) open_basedir in httpd.conf file
2) chmod for the temp folder to 1777
3) chmod of the folder from where I am uploading to 777
4) php running in safe mode ?

I was looking on the web and few of them referred to this options, wasnt sure if that might be giving me the errors.

PLEASE HELP ME WITH THIS !! I AM REALLY STUCK

Thanks for your help...really appreciate it !!
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

http://se.php.net/features.safe-mode
Read about "open_basedir".

To open a file probably means for usage of a file, open for writing as much as for reading.

Do you notice how many times I give you the manual? :wink:
Use it, it is very searchable.
nirma78
Forum Commoner
Posts: 42
Joined: Wed Sep 17, 2003 2:02 pm

Post by nirma78 »

Hey thanks for your reply !!

Well I just found out that I am not having the write privileges to the location where I am trying to save my file on server ... Will try to find out more of it and try making it work and will post here accordingly

Thanks once again
Post Reply