copy()

將伺服器的檔案複製到目的地
通常使用於檔案上傳
使用方法
copy(來源檔案,目標檔案);

範例:
upload.htm
<html>
  <head>
    <title>上傳範例</title>
  </head>
  <body>
    <form enctype="multipart/form-data" action="upload.php" method="post">
    檔案路徑:<input type="file" name="file_path"><br>
    <input type="submit" name="Submit" value="上傳">
  </body>
</html>


upload.php
<?php
  $DestDIR = "C:/www";
  $ServerFilename = "data";
  if (!empty($_FILES['file_path']['name'])) {
    if ($_FILES['file_path']['size'] > 1024*1024*2) {
      if ($_FILES['file_path']['type'] == "image/jpeg") {
        check = copy($_FILES['file_path']['tmp_name'], $DestDIR . "/" . $ServerFilename . ".jpg");
        if(check)
          echo "以上傳完成";
        else
          echo "上傳失敗";
      }
      else
        echo "檔案類型不對";
    }
    else
      echo "上傳檔案太大";
  }
  else
  {
    echo "沒有檔案";
    echo "錯誤資訊:" . $_FILES['file_path']['error'];
  }
?>

0 意見:

張貼留言