Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ PHP file upload methods exist in the database     - C # how to generate a folder or file automatically rename (Programming)

- Java look and feel mode (Facade mode) (Programming)

- Zabbix system email alert Python script (Server)

- Linux - use chroot command (Linux)

- Virt Related Command Summary (Linux)

- Virtualbox virtual machine can not copy CentOS Network (Linux)

- Linux smart small switch rfkill (Linux)

- Oracle Listener can not start (TNS-12555, TNS-12560, TNS-00525) (Database)

- Linux Basic Course: Install the software from source code (Linux)

- Snapshot DataGuard (Database)

- Proxmox VE implement KVM OpenVZ virtualization cloud computing (Server)

- Linux Detailed instructions alias settings (Linux)

- Hackers is how the invasion and control of Things devices? (Linux)

- Ubuntu Series Installation Docker (Linux)

- Linux atomic operations and synchronization mechanisms (Programming)

- Linux prohibit non-WHEEL user su command Detail (Linux)

- Kitematic how seamless and DockerFILE (Server)

- Single-node Hadoop environment to build (Server)

- Ubuntu 14.04 modify environment variables (Linux)

- To install Cinnamon desktop environment on your Ubuntu 14.04 / 12.04 (Linux)

 
         
  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:      
 
- Enable Intel Rapid Start in GNU / Linux (Linux)
- PHP security Programming Advice (Programming)
- To setup NOTRACK and TRACK of conntrack in iptables (Linux)
- How the program is executed (Programming)
- Node.js developers must know four JavaScript concepts (Programming)
- Java Concurrency - processes and threads (Programming)
- 14.04.3 Ubuntu configuration and successfully compiled source code Android 6.0 r1 (Programming)
- Oracle 11G R2 DataGuard structures (Database)
- Python configuration tortuous road of third-party libraries Numpy and matplotlib (Programming)
- Tomcat itself through simple movement separation (Server)
- MySQL script incremental backups (innobackupex) (Database)
- How to use secure FTP file transfer (Server)
- True and false in Perl (Programming)
- Python 2 Chinese garbage problem solved (Linux)
- Share and show your code on GitHub (Linux)
- Linux Operating System Security Study (Linux)
- How to create an alternative Android / iOS connected wireless hotspot AP in Ubuntu 15.04 (Linux)
- Nginx logging client ip (Server)
- Default permissions Linux file and directory permissions and hide - umask, chattr, lsattr, SUID, SGID, SBIT, file (Linux)
- Use Mop monitor stock prices at the Linux command line (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.