$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