PHP 上传文件

2022-01-09 00:00:00 file file-upload upload php html

我在用 PHP 上传文件时遇到问题.当我提交时, $_FILES[] 为空.我觉得这是一个非常n00b的问题:/

我的表格:

<form method="post" action="uploadfile.php"><输入类型=隐藏"名称=MAX_FILE_SIZE"值=300000"/>图片:<input name="ImageFile" type="file"/><br/><input type="submit" value="添加图片"/><br/></表格>

相关php.ini:

<上一页>;;;;;;;;;;;;;;;;;文件上传;;;;;;;;;;;;;;;;;;是否允许 HTTP 文件上传.文件上传 = 开;HTTP 上传文件的临时目录(如果没有,将使用系统默认值);指定的).upload_tmp_dir = "c:php5upload";上传文件的最大允许大小.upload_max_filesize = 300M

c:php5upload 可由 IUSR_HOSTNAME 写入

还有什么我应该检查的想法吗?

解决方案

确保你的表单标签有这个属性:enctype="multipart/form-data"

没有它,文件将无法上传.

I'm having a problem uploading files in PHP. When I submit, $_FILES[] is empty. I feel like this is such a n00b question :/

My form:

<form method="post" action="uploadfile.php">
<input type="hidden" name="MAX_FILE_SIZE" value="300000" />
Image: <input name="ImageFile" type="file" /><br />
<input type="submit" value="Add Image" /><br />
</form>

Relevant php.ini:

;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
upload_tmp_dir = "c:php5upload"

; Maximum allowed size for uploaded files.
upload_max_filesize = 300M

c:php5upload is writable by IUSR_HOSTNAME

Any thoughts on what else I should check?

解决方案

Make sure your form tag has this attribute: enctype="multipart/form-data"

Without it the files will not get uploaded.

相关文章