2011-05-26 62 views
0

是否有可能上傳兩個不同的文件並使用PHP以新文件名壓縮存檔?以下是我創建的表單。如何使用php上傳,存檔和重命名文件?

<form action="upload.php" method="post" enctype="multipart/form-data" name="form1" id="form1"> 
     <h1>Submit here</h1> 

    <p> 

    <label for="cat">category</label> 

    <select id="cat" name="cat" value="">Category</option> 

    <option value="csr2050">Cns</option> 

    <option value="npp2023">npp</option> 

    </select> 

    </p><p> 

     <label for="fsheet">fsheet</label> 
    <input name="fsheet" type="file" id="fsheet" /> 
    </p><p> 

     <label for="report">Report</label> 
    <input name="report" type="file" id="report" /> 
    </p><p> 

    <input type="submit" name="Submit" id="Submit" value="upload" /> 
    </form> 

這裏我想要的,怎樣寫upload.php的,可以選擇創建兩個文件的ZIP壓縮文件並將其重命名爲選定的類別值,然後把它上傳到/上傳文件夾呢?

+0

查找工具類頁面的右上角,你看到「搜索」啄? – 2011-05-26 00:09:15

回答

0

這在PHP中可能也很容易。然而,有3個功能你問這裏

  1. 上傳多個文件
  2. 壓縮檔案
  3. 重命名文件

每個人都是不同的解決方案,我的代碼可根據需要改變你的變量, 您可以查看詳細信息的zip實用程序鏈接。你也可以像,Zip文件獲得職位的數量#2爲您的每個任務

PHP ZIP files on the fly

上傳多個文件

Upload two files at once

上傳

<? 

$file_name1 = $_FILES['fsheet']['name']; 
$file_name1 = stripslashes($file_name1); 
$file_name1 = str_replace("'","",$file_name1); 
$copy = copy($_FILES['fsheet']['tmp_name'],$file_name1); 

// prompt if successfully copied 
if($copy){ 
echo "$file_name1 | uploaded sucessfully!<br>"; 
}else{ 
echo "$file_name1 | could not be uploaded!<br>"; 
} 


$file_name2 = $_FILES['report']['name']; 
$file_name2 = stripslashes($file_name2); 
$file_name2 = str_replace("'","",$file_name2); 
$copy = copy($_FILES['report']['tmp_name'],$file_name2); 

// prompt if successfully copied 
if($copy){ 
echo "$file_name2 | uploaded sucessfully!<br>"; 
}else{ 
echo "$file_name2 | could not be uploaded!<br>"; 
} 

?> 

* *郵編** 首先下載t他從拉鍊 http://www.phpclasses.org/browse/file/9524.html

<?php 
    $directoryToZip="secret"; // 
      $outputDir = $_POST['rootfolder']; 
      //$outputDir="$folder"; //Replace "/" with the name of the desired output directory. 
      $zipName="backup.zip"; 

      include_once("zip/CreateZipFile.inc.php"); 
      $createZipFile=new CreateZipFile; 
      /* 
      // Code to Zip a single file 
      $createZipFile->addDirectory($outputDir); 
      $fileContents=file_get_contents($fileToZip); 
      $createZipFile->addFile($fileContents, $outputDir.$fileToZip); 
      */ 

      //Code toZip a directory and all its files/subdirectories 
      $createZipFile->zipDirectory($directoryToZip,$outputDir); 


      $fd=fopen($zipName, "wb"); 
      $out=fwrite($fd,$createZipFile->getZippedfile()); 
      fclose($fd); 
      $msg = "Files backup successfully"; 
      //$createZipFile->forceDownload($zipName); 
      $trgtName = date("F-Y-h-i-s"). ".zip"; 
      copy ($zipName,$outputDir."/".$trgtName); 
      @unlink($zipName); 


    ?> 
+0

文件上傳腳本說不能上傳!上傳文件夾有777許可,起初我只想重命名和上傳。 – Himalay 2011-05-26 08:20:18