表单打开和提交PHP错误404

时间:2015-07-08 16:26:00

标签: php jquery forms http-status-code-404

我陷入了这个错误。当我点击“提交”按钮时,我收到了404页面未找到。它应该上传图片,在文件打开时估算。

以下是代码:

<form action="uploads/.php" method="POST" enctype="multipart/form-data">
    <input type="file" name="stuff"><br><br>
    <input type="submit" name="ceva" value="Submit">
</form>

<?php
if(isset($_POST['submit'])){
    $name = $_FILES["file"]["type"];
    //$size = $_FILES['file']['size']
    //$type = $_FILES['file']['type']

    $tmp_name = $_FILES['file']['tmp_name'];
    $error = $_FILES['file']['error'];

    if (isset ($name)) {
        if (!empty($name)) {
            $location = chmod("C:\xampp\htdocs\CeTXT\uploads", 777); 

            if  (move_uploaded_file($tmp_name, $location.$name)){
                echo 'uplods';    
            }
        } else {
            echo 'please choose a file';
        }
    }
}
?>

3 个答案:

答案 0 :(得分:0)

尝试替换此行:

if(isset($_POST['submit'])){

人:

if(isset($_POST['ceva'])){

即使是_FILE字段,也没有使用正确的POST名称。

答案 1 :(得分:0)

您改进的HTML:

<form action="uploads.php" method="POST" enctype="multipart/form-data">
    <input type="file" name="stuff"><br><br>
    <input type="submit" name="ceva" value="Submit">
 </form>

您改进的uploads.php文件:

<?php
  if(isset($_POST['ceva'])){
  $name = $_FILES["stuff"]["type"];
  //$size = $_FILES['stuff']['size']
  //$type = $_FILES['stuff']['type']

  $tmp_name = $_FILES['stuff']['tmp_name'];
  $error = $_FILES['stuff']['error'];

  if (isset ($name)) {
  if (!empty($name)) {

  $location = chmod("C:\xampp\htdocs\CeTXT\upload\", 777); 


  if  (move_uploaded_file($tmp_name, $location.$name)){
    echo 'uplods';    
  }

    } else {
      echo 'please choose a file';
      }
  }
     }
?>

答案 2 :(得分:-1)

您的表单操作似乎设置为uploads / .php,也许这需要是uploads.php?