ASP.NET文件上传范例

Standard
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<%@ Import Namespace="System" %>  
<%@ Import Namespace="System.Web.HttpPostedFile" %>  
<%@ Import Namespace="System.Web.UI.HtmlControls.HtmlInputFile" %>  
<%
  'www.yemaosheng.com
  Response.expires   =   0      
  Response.addHeader("pragma","no-cache")    
  Response.addHeader("cache-control","private")
  Response.CacheControl   =   "no-cache"
  dim i=0
  if request.queryString("state")="" then
    For i=0 to Request.Files.Count-1  
      '使用Request.Files()来逐个获取上传的文件  
      dim myFile as HttpPostedFile=Request.Files(i)  
      response.write(request.Form("text_desc"))
      myFile.SaveAs(Server.MapPath(".") & "\upload\" & myFile.FileName)
    Next
  end if
%>
<form action="" method="post" enctype="multipart/form-data" name="form_file" id="form_file">
  <textarea name="text_desc" id="text_desc"></textarea>
  <input type="file" name="filename">
  <input type="hidden" name="state" value="1">
  <input type="hidden" name="site" value="yemaosheng.com">
  <input type="submit" name="Submit" value="Submit">
</form>

PHP文件上传时关于open_basedir的报错解决

Standard

PHP Upload files to the virtual host errors:
Warning: move_uploaded_file() [function.move-uploaded-file]: open_basedir restriction in effect. File(/tmp/phpEIjcGh) is not within the allowed path(s): (/usr/local/apache/htdocs/) in /usr/local/apache/htdocs/xxxsite/upload.htm on line 21

Because web users to operate without permission belong to the “root” directory /tmp/

Solution:
Apache virtual server configuration file to add add the follow info:
<Directory “/usr/local/apache/htdocs/xxxsite”>
php_admin_value open_basedir /usr/local/apache/htdocs/xxxsite/:/tmp/
</Directory>