我是网络开发的新手。当我浏览一些教程时,我发现我无法使用php将文件上传到我的服务器。下面显示了什么是在apache2的htdocs目录中。
./index.php
./upload_action.php
./uploads
的index.html
1 <html>
2 <head>
3 </head>
4 <body>
5 <h1>New Model</h1>
6
7 <h2>Model information</h2>
8 <form enctype="multipart/form-data" action="./upload_action.php"
method="POST">
9 <p> Name:
10 <input type="text" name="textline" >
11 </P>
12
13 <p> Model to upload:
14 <input type="file" multiple name="file to upload"
value="fileupload" id="fileupload">
15 </P>
16 <br>
17 <input type="reset" value="reset">
18 <input type="submit" value="submit">
19 </form>
20
21
22 </body>
23
24 </html>
upload_action.php
1 <?php
2 $uploaddir = "/uploads/";
3 $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
4
5 echo '<pre>';
6 if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
7 echo "Success.\n";
8 } else {
9 echo "Failure.\n";
10 }
11
12 echo 'Here is some more debugging info:';
13 print_r($_FILES);
14 print "</pre>";
15 ?>
错误消息:
Failure.
Here is some more debugging info:Array
(
[file_to_upload] => Array
(
[name] => test.pdf
[type] => application/pdf
[tmp_name] => /tmp/phpz2qaQV
[error] => 0
[size] => 513536
)
)
答案 0 :(得分:1)
如果您想一次上传一个文件而不是用此
替换htmlname = "userfile"
删除multiple
它将开始工作
如果您一次上传多个文件 然后用这个替换html然后你需要运行循环来存储文件。 Refer this
如果你上传大文件时遇到麻烦,那么你可以把它放在你的php页面上
ini_set('upload_max_filesize', '10M');
ini_set('post_max_size', '10M');
ini_set('max_input_time', 300);
ini_set('max_execution_time', 300);
答案 1 :(得分:0)
你错过了一个等号。试试这个:
<form enctype="multipart/form-data" action="./upload_action.php" method="POST">