Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ PHP file upload methods exist in the database     - To set up the printer use Nagios Monitoring Server (Server)

- Linux Tutorial Share: How to sudo command to define the PATH environment variable (Linux)

- Redis configuration file interpretation (Database)

- List Leaves (Programming)

- Linux shell scripts bubble sort (Programming)

- How to build a container cluster (Server)

- Fedora 20 Installation and Configuration (Linux)

- Row-level security and application-level solutions for the new features of PostgreSQL9.5 (Database)

- Using PPA to install the lightweight theme software HotShots 2.1.0 under Ubuntu (Linux)

- Merge sort Java implementation (Programming)

- Learn to read the source code of vmstat (Linux)

- Error: Unable to establish connection with FTP SFTP server (Server)

- Linux command -nohup & (Linux)

- RPM package management tools under Linux (Linux)

- Vagrant Getting Start (Linux)

- Report generation CPU, memory, and input and output ports with the sar command (Linux)

- MySQL composite partition (Database)

- installation and configuration of the PHP environment (Apache2) under Linux (Server)

- Linux C programming and Shell Programming in the development of practical tools similarities summary (Programming)

- C # asynchronous delegates (Programming)

 
         
  PHP file upload methods exist in the database
     
  Add Date : 2018-11-21      
         
       
         
 

This paper describes examples of PHP file upload and save in the database approach. Share to you for your reference. As follows:

show_add.php file as follows:

  if (! Isset ($ _ REQUEST [ '' id '']) or $ _REQUEST [ '' id ''] == "") die ( "error : id none ");
  $ id = $ _REQUEST [ '' id ''];
  // locate a record, read out
  $ conn = mysql_connect (" localhost "," root "," admin ");
  if ($ conn) die (!" error: mysql connect failed ");
  mysql_select_db (" nokiapaymentplat ", $ conn);
  $ sql = "select * from receive where id = $ id";
  $ result = mysql_query ($ sql, $ conn);
  if ($! result) die ( "error: mysql query");
  $ num = mysql_num_rows ($ result);
  if ($ num < 1) die ( "error: no this recorder");
  $ data = mysql_result ($ result, 0, "file_data");
  $ type = mysql_result ($ result, 0, "file_type");
  $ name = mysql_result ($ result, 0, "file_name");
  mysql_close ($ conn);
  // output corresponding to the file header, and restore the original file name
  header ( "Content-type: $ type");
  header ( "Content-Disposition: attachment; filename = $ name");
  echo $ data;
>

 

show_info.php file as follows:

< php
  if (isset ($ _ REQUEST [ '' id '']) or $ _REQUEST [ '' id ''] == "!") Die ( "error:? Id none ");
  $ id = $ _REQUEST [ '' id ''];
  // locate a record, read out
  $ conn = mysql_connect (" localhost ", "root", "admin");
  if ($ conn) die (! "error: mysql connect failed");
  mysql_select_db ( "nokiapaymentplat", $ conn);
  $ sql = "select file_name, file_size from receive where id = $ id";
  $ result = mysql_query ($ sql, $ conn);
  if ($ result! ) die ( "error: mysql query");
  // If no records, the error
  $ num = mysql_num_rows ($ result);
  if ( $ num < 1) die ( "error: no this recorder");
  // The following two procedures can also write
  // $ row = mysql_fetch_object ($ result);
  // $ name = $ row- > name;
  // $ size = $ row- > size;
  $ name = mysql_result ($ result, 0 , "file_name");
  $ size = mysql_result ($ result, 0, "file_size");
  mysql_close ($ conn);
  echo "< hr > files uploaded information: ";
  echo" < br > the file ''s name - $ name ";  
  echo" < br > the file' ' s size - $ size? ";
  echo" < br > < a href = show_add.php id = $ id > attachment < / a > ";
>

submit.php file as follows:

  if (is_uploaded_file ($ _ FILES [ '' myfile ''] [ '' tmp_name ''])) {
  // have uploaded files
  $ myfile = $ _ FILES [ "myfile"];
    // set the timeout limit time, the default time is 30 seconds, set to 0 for the unlimited
    $ time_limit = 60;    
    set_time_limit ($ time_limit); //
    // the contents of the file to read the string
    $ fp = fopen ($ myfile [ '' tmp_name ''], "rb");
    if die ( "file open error") ($ fp!);
    $ file_data = addslashes (fread ($ fp, filesize ($ myfile [ '' tmp_name ''])));
    fclose ($ fp);
    unlink ($ myfile [ '' tmp_name '']);
    // file format, name, size
    $ file_type = $ myfile [ "type"];
    $ file_name = $ myfile [ "name"];
    $ file_size = $ myfile [ "size"];
    die ($ file_type);
    // connect to the database, the file is saved to the database
    $ conn = mysql_connect ( "localhost", "root", "admin");
    if die ($ conn!) ( "error: mysql connect failed");
    mysql_select_db ( "nokiapaymentplat", $ conn);
    $ sql = "insert into receive
    (file_data, file_type, file_name, file_size)
    values ( '' $ file_data '', '' $ file_type '', '' $ file_name '', $ file_size) ";
    $ result = mysql_query ($ sql, $ conn);
    // remove the following phrase just insert statement id
    $ id = mysql_insert_id ();
    mysql_close ($ conn);
    set_time_limit (30); // restore the default timeout settings
    echo "Upload successful ---";
    echo "< a href = ''? show_info.php id = $ id '' > display uploaded file information < / a > ";
 }  
  else { 
    echo" you do not have to upload any file ";  
  }  
>?

upload.php file as follows:

< html >  
< head >  
< title > file upload form < / title >  
< / head >  
< body >  
< table >  
< form enctype = '' multipart / form-data '' name = '' myform '' action = '' submit.php ''
method = '' post '' >  
< INPUT TYPE = "hidden" NAME = "MAX_FILE_SIZE" VALUE = "1000000" >
< tr > < td > Select the upload file < / td > < td >
< input name = '' myfile '' type = '' file '' > < / td > < / tr >
< tr > < td colspan = '' 2 '' > < input name = '' submit '' value = '' Upload ''   type = '' submit '' > < / td > < / tr >  
< / table >  
< / body >  
< / html >

     
         
       
         
  More:      
 
- To compile and install Clang 3.5.0 in Linux CentOS (Linux)
- CentOS achieve trash mechanism (Linux)
- How to use awk command in Linux (Linux)
- Java application server WildFly (Server)
- Ubuntu Gitolite management Git Server code base permissions (Server)
- Build the first ASP.NET 5 Web project in Mac OS X Yosemite 10.10.3 (Server)
- redis main building and disaster recovery from a cluster deployment (Database)
- Custom Android UI template Comments (Programming)
- linux smartd [FAILED] appears at startup (Linux)
- Install minimize RHEL / CentOS 7 some things need to do (Linux)
- netfilter- in kernel mode network packet operation (Linux)
- sudoers file parsing (Linux)
- Install Web-based monitoring tool: Linux-Dash (Server)
- shell script: a key optimization CentOS system (Linux)
- Flask installation environment (Linux)
- CentOS 6.6 install rsync server (Server)
- installation and configuration of the PHP environment (Apache2) under Linux (Server)
- Let OpenCV face detection score output codes (Programming)
- How to install Laravel PHP framework on CentOS 7 / Ubuntu 15.04 (Server)
- CentOS 6.4 installation environment to build Scrapy 0.22 (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.