php 檔案上傳程式(二款簡單檔案上傳程式)

來源:互聯網
上載者:User
 代碼如下 複製代碼

if(!$uploadaction):
?>

<html>
<head>
<title>檔案上傳介面</title>
</head>
<body>

<table>
<tr align="center">
<td><form enctype="multipart/form-data" name="submitform" action="upload.php" method="post">
<input type="hidden" name="max_file_size" value="1000000"><input type="hidden" name="uploadaction" value="1">
</td></tr>
<tr align="center">
<td><input name="uploadfile" type="file" size="30"></td>
</tr>
<tr align="center">
<td><input name="submit" value="提交" type="submit"></td>
<td><input name="reset" value="重設" type="reset"></td>
</tr>
</form>
</table>
</center>
</body>
</html>

<?
else:
?>

<html>
<head>
<title>檔案上傳代碼</title>
</head>
<body>

<?
$uploadaction=0;
echo "good!";
$timelimit=60; /*設定逾時限制時間 預設時間為30秒 設定為0時為不限時 */
set_time_limit($timelimit);

if(($uploadfile !="none" ))
{  
    $uploadpath=addslashes(dirname($path_translated))."\upload\"; //上傳檔案存放路徑

    $filename=$uploadpath.$uploadfile_name; //上傳檔案名稱

    if($uploadfile_size < 1024) //上傳檔案大小
    {
  $filesize=(string)$uploadfile_size." 位元組"; 
 }
     elseif ($uploadfile_size <(1024 * 1024))
     {
  $filesize=number_format((double)($uploadfile_size/1024), 1) . " kb";
     }
  else{
  $filesize=number_format((double)($uploadfile_size / (1024 * 1024)), 1) . " mb";
     }
   
    if(!file_exists($filename))
    {
         if(copy($uploadfile,$filename))
         {  echo "檔案 $uploadfile_name ($filesize)上傳成功!"; }
         else
         { echo "檔案 $uploadfile_name上傳失敗!"; }

         unlink($uploadfile);
    }
    else
    { echo "檔案 $uploadfile_name已經存在!"; }
}
else
{ echo "你沒有選擇任何檔案上傳!"; }

set_time_limit(30); //恢複預設逾時設定

?>

<br><a href = "upload.php">返回</a>

</body>
</html>

<?
endif;
?>

方法二

<html>
<head>
<title>檔案上傳</title>
</head>
<body>
<table>
<form enctype="multipart/form-data" name=myform method="post">
<tr><td>檔案上傳</td><td><input name="myfile" type="file"></td></tr>
<tr><td colspan="2"><input name="submit" value="上傳" type="submit">
</form>
<?php
if(isset($submit)){
 if($myfile != "none") {
  $upload_dir = "c:winnt emp";
  $up=copy($myfile,$upload_dir);
  if($up==1) {
   print("檔案上傳成功!");
  }
  else {
   print ("檔案上傳失敗.");
  }
  unlink ($myfile);
 }
 else {
  print("你沒有上傳任何檔案");   
 }
}
?>
</td></tr>
</table>
</body>
</html>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.