欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

讓你同時上傳 1000 個文件 (二)

 更新時間:2006年10月09日 00:00:00   作者:  
文件提交頁面既已生成,下面任務(wù)就很明確了:將提交的文件內(nèi)容保存到服務(wù)器上。

下面我們用兩種方法來實現(xiàn)這個功能:

1. 用 PHP 來保存:
我們先定義一個文件保存函數(shù) fup() 它有兩個參數(shù):
     $filename: 文件內(nèi)容
     $fname: 文件名(包含路徑)
剩下的就是寫一個循環(huán)將文件依次寫入服務(wù)器。這里要簡單說明一下:
PHP 對于上傳文件的處理是這樣的:如果提交的文件框我為 file0, 那么提交給 PHP 的文件內(nèi)容保存在變量 $file0 中,而文件名則保存在 $file0_name 中。這樣在這個循環(huán)中我要做的就是將提交頁面提交的內(nèi)容分解出來,實現(xiàn)過程請看下面的代碼。

fileup.php
----------------------------------------------------------------------
<?
    function fup($filename,$fname)
    {        If($filename != "none") {
                copy($filename,$fname);
                unlink($filename);  
            }
    }

    for($i=0;$i<$cnt;$i++)
    {
        $ffnn="file".$i;
        $ffnnname=$ffnn."_name";
        $ffpath="path".$i;

        //print $$ffnn;
        print $$ffnnname;
        print "<br>";

        fup($$ffnn,$$ffpath.$$ffnnname); //"../www/test/tmp/"
    }
?>
----------------------------------------------------------------------

2. 用 PERL 來保存:
它們實現(xiàn)的原理完全一樣,在此不多說,請看代碼:

fileup.cgi(fileup.pl)
----------------------------------------------------------------------
#!/usr/bin/perl  

use CGI qw/:standard/;  

if ($ENV{'CONTENT_TYPE'} !~ /multipart/form-data/) {  
  print "Cache-Control: no-cachenPragma: no-cachen" .  
    "Content-Type: text/htmlnn" .  
    "<html><body>Your web browser cannot upload files. Sorry.</body></html>";  
  exit 0;  
}


$cntfile=param('cnt');
print header;  
print start_html;  
#print "Receiving Please wait....";

&g_head;

#$writed = '../www/test/tmp/';

for ($i=0;$i<$cntfile;$i++){
    $paramfile = 'file'.$i;
    $parampath='path'.$i;

    $writed=param($parampath);

    &upfile;
    &g_body;
}

&g_bott;

#<<<<<<<<<<<<<<<<<<<<<以下為自定義過程<<<<<<<<<<<<<<<<<<<<<<<<<

sub upfile
{
    $maxdata = 512000;  
#    $writed = '../www/test/tmp/';  


    $strRFname=reverse $xfile;
    $intIndex=index($strRFname,'\');
    $strNetFname=substr($strRFname,0,$intIndex);
    $strNetFname=scalar reverse $strNetFname;

     
    if((stat $xfile)[7]>$maxdata){  
        print "Status: 411 Size Not Allowedn" .  
            "Content-Type: text/htmlnAllow: POSTnn" .  
            "<html><head><title>411 411 Size Not Allowed</title></head><body><h1> You got big problem.  Try again.</h1></body></html>n";  
        exit 0;  
    }  

     
    binmode $xfile;  
    use File::Copy;  
    copy($xfile,$writed.$strNetFname);  
}

sub g_head{
    print '<table border=1 align=center>';
    print '<tr><td colspan=3 align=center>文件上傳結(jié)果(Upload Result)</td></tr>';
    print '<tr align=center>';
    print '    <td>SourceFile:</td>';
    print '    <td>DestFile:</td>';
    print '    <td>Upload</td>';
    print '</tr>';
}

sub g_body{
    print '<tr>';
    print '    <td>'.$xfile .'</td>';
    print '    <td>'.$writed.$strNetFname.'</td>';
    print '    <td>OK!</td>';
    print '</tr>';
}

sub g_bott{
    print '</table>';
}
----------------------------------------------------------------------
如有好的建議請 Email: gearsoft@netease.com  

【本文版權(quán)歸作者gearsoft與奧索網(wǎng)共同擁有,如需轉(zhuǎn)載,請注明作者及出處】     

相關(guān)文章

  • php strftime函數(shù)的詳細用法

    php strftime函數(shù)的詳細用法

    這篇文章主要介紹了php strftime函數(shù)的詳細用法,strftime() 函數(shù)根據(jù)區(qū)域設(shè)置格式化本地時間/日期,一般情況下可以用來時間格式化,需要的朋友可以參考下
    2018-06-06
  • php結(jié)合表單實現(xiàn)一些簡單功能的例子

    php結(jié)合表單實現(xiàn)一些簡單功能的例子

    這兩天學(xué)了寫表單。總結(jié)于此,以備忘。
    2011-06-06
  • PHP getNamespaces()函數(shù)講解

    PHP getNamespaces()函數(shù)講解

    今天小編就為大家分享一篇關(guān)于PHP getNamespaces()函數(shù)講解,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-02-02
  • PHP_MySQL教程-第一天

    PHP_MySQL教程-第一天

    PHP_MySQL教程-第一天...
    2007-03-03
  • 最新評論