WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Save and restore files into postgresql database (PHP SCRIPT) PHP CLASS
Categories : PHP, Databases, PostgreSQL, Filesystem Click here to Update Your Picture
ivan valadares
Date : Dec 29th 2005
Grade : 5 of 5 (graded 1 times)
Viewed : 6108
File : 4283.php
Images : No Images for this code example.
Search : More code by ivan valadares
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?php

function addImage($conn,$filename)
{
 
// Open and read the file that was uploaded
 
$fp = fopen($filename, "r");
  if(
$fp == false)
      echo
"Error opening file";
 
// Begin a PostgreSQL transaction
 
pg_exec("begin");
 
 
// create the large object and get the lo id
 
$lo_id = pg_locreate();
 
 
// have postgresql open the large object for writing
 
$lo_fp = pg_loopen($lo_id, "w");
 
 
// for ever 8192 bytes of the uploaded file
 
while($nbytes = fread($fp, 8192)) {
   
   
// write to the large object
   
$tmp = pg_lowrite($lo_fp, $nbytes);
   
   
// handle possible error
   
if($tmp < $nbytes) {
      echo
"error while writing large object";
    }
   
  }
 
 
// close the large object
 
pg_loclose($lo_fp);
 
 
// commit the postgresql transaction
 
pg_exec("commit");
 
 
// close the uploaded file
 
fclose($fp);
 
 
  if (!
is_int($lo_id)) {
     
// return false
   
return false;
  }
   
  if (
is_int($lo_id)) {
   
// return large object id
   
return $lo_id;
  }
 
}

function
ReadImage($lo_id,$filesize)
{
   
pg_exec("begin");
   
   
$handle = pg_lo_open($lo_id,"r");
   
$data = pg_lo_read($handle,$filesize);
   
//pg_lo_close($lo_fp);

    //pg_exec($conn,"commit");
   
return $data;   
}

function
WriteImageToFile($id,$filename,$filesize)
{
   
$data = ReadImage($id,$filesize);
   
$f = fopen($filename,"w");
    if(
fwrite($f,$data) == FALSE)
    {
       
$message ="ERROR";//getTokenValue("CANT_WRITE_FILE",$lang)." dbresource.txt";
   
}
   
fclose($f);
}
?>




-------- Database ----------------
CREATE TABLE images (
    name text,
    image oid,
    filesize bigint
);


---------- File to Database Exemple ------------

<?
include("image.php");
$filetosave="HPIM0551.JPG" // file to save in the database
$loId = addImage($conn,$filetosave);
$id_Desc = $filetosave;
$fsize=filesize("HPIM0551.JPG");
$sql = "INSERT INTO images(name,value,filesize) VALUES('$id_Desc','$loId','$fsize')";
pg_query($sql);
?>


-------- Database to Files Exemple ------------
<?
include("image.php");
$sql = "Select value,name,filesize FROM images";
$res = Query($conn,$sql);
$dir = "C:\\images\\"; // directory
while(Fetch($res)){
        if (
Cell($res,2)){
               
WriteImageToFile(Cell($res,0),$dir.Cell($res,1),Cell($res,2));
        }
}
?>



PostGreSQL and MySQL 2 in 1 db Manager
Categories : PHP, PHP Classes, Databases, PostgreSQL, MySQL
Script for postgresql to walk through the results limiting the results shown per page.
Categories : PostgreSQL, Databases, PHP
Simple pipe delimited file export program that downloads to a local machine
Categories : PHP, Filesystem, Databases, MySQL, HTTP
Monthly and Daily Upcoming Events calendar.
Categories : Date Time, PostgreSQL, PHP, Calendar, Databases
Convert a File database into MySQL
Categories : PHP, Filesystem, Databases, MySQL, Beginner Guides
Logs hits to any page which includes it. Automatically utilises page access information left behind by PHP/FI2.0.
Categories : Databases, PHP, mSQL, Databases
AUTH (.htaccess style) - a login system that uses PostgreSQL.
Categories : PHP, Authentication, Databases, PostgreSQL
DBE - Database Expander: Edit PostgreSQL individual database tables online via your Web browser!
Categories : PostgreSQL, Complete Programs, Databases, PHP Classes, PHP
This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server.
Categories : Databases, MySQL, Complete Programs, PHP, Databases
Is there any way to test that the $result has null values or not without reading the field values in the results in postgre?
Categories : PostgreSQL, PHP, Databases
Postgresql Database Backup And Restore PHP script
Categories : PHP, Databases, PostgreSQL
This is a database wrapper for PostgreSQL, but can be simply modified for any other database type.
Categories : Databases, PostgreSQL, PHP
This is a function to display a table for Postgres results. This this code in an include file, require it, and call ShowResults($result) whenever you need to see what your queries result in.
Categories : Databases, PHP, PostgreSQL
A PHP Script that shows how to use FTP to run a shell script, read two local files and update data in a database.
Categories : PHP, Filesystem, FTP, Date Time, Databases
This is Yet Another Sql Abstraction Library. Include it in your script and you can use the most important SQL functions without worrying about the SQL backend.
Categories : Databases, PHP, ODBC, MySQL, PostgreSQL