php上传图片获取$ _FILE ['文件']的未定义索引,也未检测到提交按钮为isset

时间:2015-10-11 17:04:52

标签: php

我有2个文件。一个用于图像上传。一个用于评估。 第一档:

p1

第二档:

<html>
  <head><title>Upload File</title></head>
  <body>
  <h2>Upload File</h2>
 <form method="post" action="Assignment7_backend.php" enctype="multipart/form­data"><input type='hidden' name='MAX_FILE_SIZE' value='50000'>
 Your file: <input type="file" name="image">
 <br/> 
 <input type="submit" value="Send it!">
 </form>
  </body>
</html>

我希望上传文件,但在我选择文件并提交后,它显示错误:<html> <head><title>Upload File</title></head> <body> <h2>Upload File now</h2> <?php if (is_uploaded_file($_FILES['image']['tmp_name'])) { if($_FILES['image']['error'] != UPLOAD_ERR_OK) { print "<p>File not uploaded successfully!</p>"; print "<p><a href='Assignment7_upload.php'>Try Uploading Again</a> </p>" ; } else { move_uploaded_file($_FILES['image']['tmp_name'], "./images/" . $_FILES['image']['name'] ) or die("can't move file"); print "<p>Success!</p>"; } } else { print("<p>File is not uploaded</p>"); print("<p>".$_FILES['image']['error']."</p>"); if (!isset($_POST['submit'])) { print("<p>cannot even detect submit</p>"); } } ?> </body> </html> 索引未定义。另外,$_FILE['image']未设置。我的代码出了什么问题?

1 个答案:

答案 0 :(得分:1)

您在此处发布的enctype错误。因此表单无法提交任何图像/文件 我不知道这是不是打字错误,或者你的代码确实错了 正确的是:enctype="multipart/form-data"