5/4/11

How to Perform File Uploads From PHP to Oracle

PHP is a scripting language developers use in creating web applications. When developing complex websites, PHP works in conjunction with other technologies such as online databases. One of the most popular database systems used by top companies around the world is Oracle. With its large base of users, learning how to create web applications that work with Oracle is an excellent skill to acquire. A good place to start is by learning how to create scripts that allow users to upload files and store them in an Oracle database.
    • 1

      Design a file upload form. Using Notepad or an HTML editor such as Microsoft FrontPage or Adobe Dreamweaver, create a web form that allows for file uploads. File upload pages have three basic elements: the text field for the file name, the "Browse" button to choose files for uploading, and the "Submit" button. Indicate a PHP file that handles the file upload as the action to your form, and "post" as your method. For example:

      <form method="post" action="upload_to_oracle.php">

    • 2

      Create a database connection script. Using Notepad, write a script to connect to the Oracle database. Use the oci_connect() function to do so:

      $connectdb = oci_connect('username', 'password', 'database_name')

      Replace "username" and "password," to your own Oracle username and password, and "database_name" to the name of the Oracle database you are connecting to. For the application to successfully upload files onto the database, the Oracle database account you are logging onto needs to have the privileges to insert and update information on the database.

    • 3

      Create a script that obtains the data from the form and uploads it to the database. Use the $_FILES() function to grab the file to be uploaded, then type in the SQL statement needed for data insertion:

      $sql = "INSERT INTO files (filename) VALUES ('$myfile')";

      Using the oci_parse () and oci_execute() PHP functions, process the SQL to be interpreted by the Oracle database, and execute the SQL statement to insert the file in your database:

      $sql_statement = oci_parse($connectdb,$sql);

      oci_execute($sql_statement);

    • 4

      Save your PHP file.

    • 5

      Upload both the web form and the PHP file on your web server. On your browser, open the web form and use it to upload a file to your Oracle database.

  • No comments: