Question regarding uploading files to database
Moderator: General Moderators
Question regarding uploading files to database
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
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
- Heavy
- Forum Contributor
- Posts: 478
- Joined: Sun Sep 22, 2002 7:36 am
- Location: Viksjöfors, Hälsingland, Sweden
- Contact:
Read more carefully about how to recieve uploaded files, and you'll get it.
http://se2.php.net/manual/en/features.f ... ost-method
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.
- Heavy
- Forum Contributor
- Posts: 478
- Joined: Sun Sep 22, 2002 7:36 am
- Location: Viksjöfors, Hälsingland, Sweden
- Contact:
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.
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";
}
?>
/*********************************************************/
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";
}
?>
/*********************************************************/
- Heavy
- Forum Contributor
- Posts: 478
- Joined: Sun Sep 22, 2002 7:36 am
- Location: Viksjöfors, Hälsingland, Sweden
- Contact:
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.
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.
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 !!
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 !!
- Heavy
- Forum Contributor
- Posts: 478
- Joined: Sun Sep 22, 2002 7:36 am
- Location: Viksjöfors, Hälsingland, Sweden
- Contact:
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?
Use it, it is very searchable.
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?
Use it, it is very searchable.