Unzip the uploaded text file to compress the package and insert the extracted text file contents into the database

Source: Internet
Author: User

$content  = file_get_contents ($_files["File" ["Tmp_name"]), $ret->content =  $content;   (file_exists ("/var/www/api/uploads//"  . $_files["file"] ["name"]) {echo $_files["file"] [" Name "] . "  already exists.  ";} Else{move_uploaded_file ($_files["file"] ["Tmp_name"], "/var/www/api/uploads/"  . $_files["file" ["Name"] ]);echo  "upload file stored in: "  .  "/var/www/api/uploads/"  . $_ files["File" ["Name"];} $zip  = new ZipArchive; $filename  = $_files["file" ["name"]; $path  =  "/var/www /api/uploads "; if (!file_exists ($path.") /". $filename)") {die ("the zip file  $filename  not exist!");} Open the compressed package $resource =  $zip->open ($path. /". $filename);if  ($resource  === true)  {echo " unzip successed! "; /unzip to the server upload directory under $zip->extractto ('/var/www/api/uploads '); $array 1 = get_object_vars ($zip); $bigarr  = array ();for  ($i =0; $i < $array 1[' numfiles ']; $i + +) {//based on the file name within the compression, get the text stream of the file $stream =  $zip- >getstream ($zip->getnameindex ($i)), $str  = stream_get_contents ($stream); $str  = str_ Replace (Array ("\ r \ n",  "\ r",  "\ n"),  ",",  $str); $arr  = explode (",", $str); $bigarr  = array_merge ($bigarr,  $arr); unset ($STR);} $zip->close (); Echo count ($bigarr); $device  = new device (); $device->add ($bigarr,  ' 2015-12-21 ',  ' 2015-12-21 ',  ' 2000 ');}  else {echo  ' Unzip failure!, code: '  .  $resource;}
Global $pdo; $sql = ' INSERT into device VALUES '; $arr = Array_fill (0, Count ($data), "(?, $listing _date, $create _time, $creat E_uid, 0, 0); $sql. = Join (', ', $arr); $stmt = $pdo->prepare ($sql); $stmt->execute ($data);

Splicing SQL statements for one-time insertion:


Unzip the uploaded text file to compress the package and insert the extracted text file contents into the database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.