Category Archives: 数据读取或下载

php 读取csv中每一行数据

$csv_file=$request->getFile(’post_csv’); $handle = @fopen($csv_file[’tmp_name’], "r"); if ($handle){ while (!feof($handle)) { $buffer = trim(fgets($handle, 4096)); echo "<br/>".$buffer; } fclose($handle); } html中:<input type="file" name="post_csv" >   trim() 函数从字符串的两端删除空白字符和其他预定义字符。 也可以利用 explode 函数分割字符串到数组,然后循环数组即可

php 使用php导出xls文件并提示下载另存

PHP代码 1. header(“Pragma: public“); 2. header(“Expires: 0“); 3. header(“Cache-Control: must-revalidate, post-check=0, pre-check=0“); 4. header(“Content-Type: application/force-download“); 5. header(“Content-Type: application/download“); 6. header(“Content-Disposition: attachment;filename=$filename“); 7. header(“Content-Transfer-Encoding: binary “); 或者 PHP代码 1. header(“Pragma: public“); 2. header(“Expires: 0“); 3. header(“Content-Type: application/force-download“); 4. header(“Content-Type: application/download“); 5. header(“Content-Disposition: attachment;filename=$fn“); 6. header(“Content-Transfer-Encoding: binary “);//二进制

php 下载数据(生成word文件)

//以xls下载, 也就是word下载 class AdminProduct_CsvDownloadAction extends BeauBeauAction {   protected function configuration($config) { $config->defaultView = array(’AdminProduct’, ‘ListInit’); $config->requestMethods = Request::POST; $config->secure = true; $config->credential = BEAUBEAU_ADMIN_MENU_PRODUCT_MAINTENANCE; $config->transactionType = TransactionType::REQUIRED; }   public function handleError () { return View::NONE; }   public function execute () { $context = $this->getContext(); $request = $this->getRequest(); $constant = $this->getConstants(); $controller = [...]

php 下载数据(生成txt文件)

生成Albert推荐信息Log $log_file = AG_WEBAPP_DIR.’/log/commend.txt’;//注:表示路径,即存放的位置 $log_content = date(“Y/n/d G:i”) . “\t” . $mobile . “\t” . $webSite . “\t” . session_id() . “\n”; $log_block = $constant['robot']; //注:$mobile $webSite 表示从前一个页面取得的数据 $is_bot = false; foreach ($log_block as $key=>$value) { if (eregi($value, $_SERVER['HTTP_USER_AGENT'])) { $is_bot = true; break; } } if ($is_bot == false) { $fp = @fopen($log_file, ‘a+’); [...]