php excel上傳到指定目錄並重命名為指定名字

上傳頁面
<div class="out_in">
<div class="my_title">二、數據導入</div>
<div class="content">
<form name="data_in" id="data_in" action="data_in.php" method="post" enctype="multipart/form-data" style="margin-top:20px;">
<input type="hidden" name="filename" />
選擇文件:<input name="file" Type="file" style="width:350px;height:25px;font-size:18px;" />
<input type="button" value="導入" onClick="submit()" style="width:70px;height:25px;font-size:18px;"/>
</form>
</div>
</div>

數據處理頁面:

<?php
include("../config/string.php");
include("../config/system.ini.php");
include("../config/const.ini.php");
include("../lib/session.php");
include("../lib/db.php");
include("../lib/html.php");
include("../lib/system.php");
include("../fun/sys.php");
include("../lib/zip.php");
check_session();
$_SESSION["help_id"]=6;
h_start("../",1);
h_css("css/data.css");
h_css("../css/tab.css");
h_title(STR_VOUCHER,"style=\"background-color:#d4ecfc;\"");
set_navigation("../homepage.php,系統首頁,data.php,導入導出");
$mylink=db_link();
if($_POST){
$filename=$_FILES["file"]["name"];
$type=substr($filename,strlen($filename)-3,3);
if($type!="zip"){
die(h_alert("非法文件格式!","data.php"));
}
move_uploaded_file($_FILES["file"]["tmp_name"],$filename);
if(!file_exists($filename)){
die(h_alert("文件上傳失敗!","data.php"));
}
$zip_name=$filename;
$zip = new PclZip($zip_name);//解壓文件
$zip->extract();
$tmp=substr($filename,0,strlen($filename)-4);
$filename=$tmp.".skcg";
data_in($filename,$mylink,"data.php");//讀入數據
h_alert("導入成功!","data.php");
($zip_name,"upload/".$zip_name);
unlink($zip_name);
unlink($filename);
}
?>

這是我程序源碼中自己寫的一個 功能,作用是將一個加密的mysql插入、修改,刪除語句文件壓縮包上傳到伺服器解包解密導入資料庫,希望對你有幫助

㈡ 直接把excel文件上傳到伺服器,然後用php後台語言讀入excel,求完整的代碼,最好是能提供一個實力,嘻嘻 ,

用PHPExcel,PHPExcel是相當強大的 MS Office Excel 文檔生成類庫。

你上它的官/網把程序包下/載下來,裡面有 PHPExcel 的程序、還有30個實常式序和三個文檔。
看一下其中的開發文檔你就會用了。

讀取(這段在開發文檔里有的,在13頁):
require_once '../Classes/PHPExcel/IOFactory.php';

$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setReadDataOnly(true);

$objPHPExcel = $objReader->load("test.xlsx");
$objWorksheet = $objPHPExcel->getActiveSheet();

echo '<table>' . "\n";
foreach ($objWorksheet->getRowIterator() as $row) {
echo '<tr>' . "\n";
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
foreach ($cellIterator as $cell) {
echo '<td>' . $cell->getValue() . '</td>' . "\n";
}
echo '</tr>' . "\n";
}
echo '</table>' . "\n";
?>

㈢ php上傳excel文件,如何讀取文件中的信息

網頁上傳文件並點擊打開excel、word文檔:
<?php
if($submit && $testfile <> "none ") {
$path= "/home/httpd/html/ "; //絕對路徑,注意Linux和Windows下面的格式,windows格式為:c:\\apache2\\htdocs\\
$filename=$testfile_name;
if (!@($testfile,$path.$filename)) {
echo "復制文件失敗... <br> \n ";
exit();
}
@unlink($testfile);
echo "文件上傳成功!地址為: <a href=\ "$filename\ "> 下載 </a> ";
exit;
}
?>
<form action= " <?php echo $PHP_SELF;?> " method= "post " enctype= "multipart/form-data ">
<input name= "testfile " type= "file " size=20 enctype= "multipart/form-data ">
<input type=submit name=submit value= "開始上傳 ">
</form>

㈣ 利用php導入excel文件

【步驟1】在前台html頁面進行上傳文件

<formmethod="post"action="php文件"enctype="multipart/form-data">
<h3>導入Excel表:</h3><inputtype="file"name="file_stu"/>
<inputtype="submit"value="導入"/>
</form>

【步驟2】在對應的php文件進行文件的處理

if(!empty($_FILES['file_stu']['name']))
{$tmp_file=$_FILES['file_stu']['tmp_name'];$file_types=explode(".",$_FILES['file_stu']['name']);$file_type=$file_types[count($file_types)-1];
/*判別是不是.xls文件,判別是不是excel文件*/if(strtolower($file_type)!="xls"){$this->error('不是Excel文件,重新上傳');}
/*設置上傳路徑*/$savePath=SITE_PATH.'/public/upfile/Excel/';
/*以時間來命名上傳的文件*/$str=date('Ymdhis');$file_name=$str.".".$file_type;
/*是否上傳成功*/if(!($tmp_file,$savePath.$file_name)){$this->error('上傳失敗');}
/*

*對上傳的Excel數據進行處理生成編程數據,這個函數會在下面第三步的ExcelToArray類中

注意:這里調用執行了第三步類裡面的read函數,把Excel轉化為數組並返回給$res,再進行資料庫寫入

*/$res=Service('ExcelToArray')->read($savePath.$file_name);
/*

重要代碼 解決Thinkphp M、D方法不能調用的問題

如果在thinkphp中遇到M 、D方法失效時就加入下面一句代碼

*/

//spl_autoload_register(array('Think','autoload'));

/*對生成的數組進行資料庫的寫入*/

foreach($resas$k=>$v){if($k!=0){$data['uid']=$v[0];$data['password']=sha1('111111');$data['email']=$v[1];
$data['uname']=$v[3];
$data['institute']=$v[4];$result=M('user')->add($data);if(!$result){$this->error('導入資料庫失敗');}}}
}
【步驟3】ExcelToArrary類,用來引用phpExcel並處理Excel數據的
{
publicfunction__construct(){
/*導入phpExcel核心類注意:你的路徑跟我不一樣就不能直接復制*/include_once('./Excel/PHPExcel.php');}
/**

* 讀取excel $filename 路徑文件名 $encode 返回數據的編碼 默認為utf8

*以下基本都不要修改

*/

publicfunctionread($filename,$encode='utf-8'){
$objReader=PHPExcel_IOFactory::createReader('Excel5');
$objReader->setReadDataOnly(true);
$objPHPExcel=$objReader->load($filename);
$objWorksheet=$objPHPExcel->getActiveSheet();
$highestRow=$objWorksheet->getHighestRow();$highestColumn=$objWorksheet->getHighestColumn();$highestColumnIndex=PHPExcel_Cell::columnIndexFromString($highestColumn);$excelData=array();for($row=1;$row<=$highestRow;$row++){for($col=0;$col<$highestColumnIndex;$col++){$excelData[$row][]=(string)$objWorksheet->getCellByColumnAndRow($col,$row)->getValue();}}return$excelData;
}

}

㈤ php如何實現上傳導入excel數據

難道你導入的時候不是選擇的本地 文件嗎?input框獲取之後 提交過去就可以導入了啊 phpexcel中有例子的啊 可以看看簡單的嘛 基本上 按那個例子改點東西就可以用了啊

㈥ 原生PHP代碼實現excel導入,並添加數據到資料庫.

我用的代碼是:
<?
//連接資料庫文件
$connect=mysql_connect("localhost","admin","admin") or die("鏈接資料庫失敗!");
//連接資料庫(test)
mysql_select_db("testcg",$connect) or die (mysql_error());

$temp=file("test.csv");//連接EXCEL文件,格式為了.csv
for ($i=0;$i <count($temp);$i++)
{
$string=explode(",",$temp[$i]);//通過循環得到EXCEL文件中每行記錄的值
//將EXCEL文件中每行記錄的值插入到資料庫中
$q="insert into ceshi (name,num,dom) values('$string[0]','$string[1]','$string[2]');";
mysql_query($q) or die (mysql_error());

if (!mysql_error());
{
echo " 成功導入數據!";
}
echo $string[4]."\n";
unset($string);
}
?>

--------------------------------------------------------------------------------
phpexcel或者pear的一個組件 ,國內有一個excelclass的插件
都是用來處理excel的,前2個功能都比較強大,對編碼的支持也都不錯,推薦使用pear的那個,名字好像叫spreadsheet reader

phpexcel比較費資源,不過並不是所有的excel都能讀取

樓主可以到這里去看看 pear.php.net
--------------------------------------------------------------------------------
頂樓上的回答~~順便接個分!嘿嘿
--------------------------------------------------------------------------------
AdO直接上傳

注意有些字元mysql或ADO可能不支持
--------------------------------------------------------------------------------
首先確認你的資料庫是什麼編碼的,以utf-8為例,
你首先打開excel 文件,然後保存,選擇為另存為.csv文件。
然後用文本編輯器打開.csv文件,另存為utf-8的csv
然後你寫php 可以使用php 的getcsv 打開(這樣確保你有的欄位中含有,而導致解析錯誤),然後把解析的結果導入到資料庫中。
然後完了。

㈦ php 上傳excel 表格 PHPExcel類,出現錯

ZipArchive library is not enabled:出現這個錯誤說明是程序在調用'ZipArchive' 這個類的時候沒有成功,原因是由於在安裝php的時候沒有增加php zip的支持(非zlib)。
請在php.ini找到extension=php_zip.dll並把前面的分號去掉(如果沒有,請添加extension=php_zip.dll此行並確保php_zip.dll文件存在相應的目錄),保存後重啟php即可。

在Unix/Linux下的解決辦法:
1、在Linux下沒有php_zip.dll這個文件(有也不會起作用的),所以需要重新編譯一下php的zip模塊。具體安裝方法如下:
cd /usr/src
wget
tar -zxvf zip
cd zip-1.x.x
phpize
./configure
make
sudo make instal
其中, 在最後使用make install命令的時候,可能需要用到root的許可權,所以建議使用sudo來運行。安裝完之後,屏幕上會提示zip.so的位置。然後將其記錄下來,如:/usr/local/lib/php/extensions/zip.so。
2、使用root許可權修改php.ini(通常可能會在/usr/local/lib/文件夾下,不過視當初安裝php而定,可以通過phpinfo()來查看):
增加extension = /usr/local/lib/php/extensions/zip.so,然後同樣在php.ini文件中,將 zlib.output_compression = Off 改為 zlib.output_compression = On ;
3、最後別忘了重啟一下Apache:apachectl restart;
這個針對php的zip模塊就安裝完成了,能夠在php中使用ZipArchive類了。

㈧ 如何用PHP做文件上傳,和在網頁上點擊打開Word或Excel文件

<?php
if($submit && $testfile<> "none") {
$path="/home/httpd/html/"; //絕對路徑,注意Linux和Windows下面的格式,windows格式為:c:\\apache2\\htdocs\ $filename=$testfile_name;
if (!@($testfile,$path.$filename)) {
echo "復制文件失敗...<br>\n";
exit();
}
@unlink($testfile);
echo "文件上傳成功!地址為:<a href=\"$filename\">下載</a>";
exit;
}
?>
<form action="<?php echo $PHP_SELF;?>" method="post" enctype="multipart/form-data">
<input name="testfile" type="file" size=20 enctype="multipart/form-data">
<input type=submit name=submit value="開始上傳">
</form>

㈨ 導入excel文件,後端php處理導入的數據並存入資料庫,需要前後端結合的demo!

thinkphp3.2和phpexcel導入最基本用法
先整個最基礎的代碼,理解了這個,後面的就非常簡單了

$file_name='./Upload/excel/123456.xls';
import("Org.Util.PHPExcel");
import("Org.Util.PHPExcel.IOFactory");
$objReader=PHPExcel_IOFactory::createReader('Excel5');
$objPHPExcel=$objReader->load($file_name,$encode='utf-8');
$sheet=$objPHPExcel->getSheet(0);
$highestRow=$sheet->getHighestRow();//取得總行數
$highestColumn=$sheet->getHighestColumn();//取得總列數

$s=$objPHPExcel->getActiveSheet()->getCell("A2")->getValue();

表格內容:

publicfunctionupload(){
$files=$_FILES['exl'];


//exl格式,否則重新上傳
if($files['type']!='application/vnd.ms-excel'){
$this->error('不是Excel文件,請重新上傳');
}

//上傳
$upload=newThinkUpload();//實例化上傳類
$upload->maxSize=3145728;//設置附件上傳大小
$upload->exts=array('xls');//設置附件上傳類型
$upload->rootPath='./Upload/';//設置附件上傳根目錄
$upload->savePath='excel/';//設置附件上傳(子)目錄
//$upload->subName=array('date','Ym');
$upload->subName='';
//上傳文件
$info=$upload->upload();

$file_name=$upload->rootPath.$info['exl']['savepath'].$info['exl']['savename'];
$exl=$this->import_exl($file_name);

//去掉第exl表格中第一行
unset($exl[0]);

//清理空數組
foreach($exlas$k=>$v){
if(empty($v)){
unset($exl[$k]);
}
};
//重新排序
sort($exl);

$count=count($exl);
//檢測表格導入成功後,是否有數據生成
if($count<1){
$this->error('未檢測到有效數據');
}

//開始組合數據
foreach($exlas$k=>$v){

$goods[$k]['goods_sn']=$v;

//查詢資料庫
$where['goods_sn']=array('like','%'.$v.'%');
$res=M('goods')->where($where)->find();

$goods[$k]['goods_name']=$res['goods_name'];
$goods[$k]['goods_thumb']=$res['goods_thumb'];
if($res){
//是否匹配成功
$goods[$k]['is_match']='1';
$f+=1;
}else{
//匹配失敗
$goods[$k]['is_match']='0';
$w+=1;
}

}
//實例化數據
$this->assign('goods',$goods);
//print_r($f);

//統計結果
$total['count']=$count;
$total['success']=$f;
$total['error']=$w;
$this->assign('total',$total);

//刪除Excel文件
unlink($file_name);
$this->display('info');

}
/*處理上傳exl數據
*$file_name文件路徑
*/
publicfunctionimport_exl($file_name){
//$file_name='./Upload/excel/123456.xls';
import("Org.Util.PHPExcel");//這里不能漏掉
import("Org.Util.PHPExcel.IOFactory");
$objReader=PHPExcel_IOFactory::createReader('Excel5');
$objPHPExcel=$objReader->load($file_name,$encode='utf-8');
$sheet=$objPHPExcel->getSheet(0);
$highestRow=$sheet->getHighestRow();//取得總行數
$highestColumn=$sheet->getHighestColumn();//取得總列數

for($i=1;$i<$highestRow+1;$i++){
$data[]=$objPHPExcel->getActiveSheet()->getCell('A'.$i)->getValue();
}
return$data;
}

有問題一定要及時弄清楚