$content = file_get_contents($_FILES["file"]["tmp_name"]); $ret->content = $content; if (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!"); } //打开压缩包 $resource = $zip->open($path."/".$filename); if ($resource === TRUE) { echo "Unzip successed!"; //解压缩到服务器上传目录底下 $zip->extractTo(‘/var/www/api/uploads‘); $array1 = get_object_vars($zip); $bigarr = array(); for ($i=0;$i<$array1[‘numFiles‘];$i++){ //根据压缩内的文件名称,获取该文件的文本流 $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, $create_uid, 0, 0)"); $sql .= join(‘,‘, $arr); $stmt = $pdo->prepare($sql); $stmt->execute($data);
拼接SQL语句进行一次性插入:
时间: 2024-10-03 22:29:45