无法在wampserver上传图片

时间:2014-04-21 03:44:04

标签: ajax html5

我需要一些建议/帮助。我试图上传图片,但wampserver一直向我显示此错误(警告:POST内容长度为80237字节,超过了第0行上未知的750字节限制文件未上传!)但是我尝试更改php.ini设置,但它仍然相同,如果有人可以在这里提供帮助,将不胜感激。感谢

这是我的代码

  <!doctype html>
  <html>
  <head lang="en">
<meta charset="utf-8">
<title>Ajax Image Upload with jQuery - w3bees.com</title>
<!-- scripts -->
<script type="text/javascript" src="js/jquery.7.1.min.js"></script>
<script type="text/javascript" src="js/jquery.form.js"></script>
<script type="text/javascript" src="js/script.js"></script>
<style>
a, h1{
    font-family: Georgia, "Times New Roman", Times, serif;
    font-size: 170%;
    color: #645348;
    font-style: italic;
    text-decoration: none;
    font-weight: 100;
    padding: 10px;
}
body{
    font: 14px Arial,Tahoma,Helvetica,FreeSans,sans-serif;
    text-transform: inherit;
    color: #582A00;
    background: #E7EDEE;
    width: 100%;
    margin: 0;
    padding: 0;
}
.wrap{
    width: 700px;
    margin: 10px auto;
    padding: 10px 15px;
    background: white;
    border: 2px solid #DBDBDB;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
    text-align: center;
    overflow: hidden;
}
#preview {
    color: red;
}
#preview img{
    margin-top: 30px;
    max-width: 100%;
    border: 0;
    border-radius: 3px;
    -webkit-box-shadow: 0px 2px 7px 0px rgba(0, 0, 0, .27);
    box-shadow: 0px 2px 7px 0px rgba(0, 0, 0, .27);
    overflow: hidden;
}
input[type="submit"]{
    border-radius: 10px;
    background-color: #61B3DE;
    border: 0;
    color: white;
    font-weight: bold;
    font-style: italic;
    padding: 6px 15px 5px;
    cursor: pointer;
}
</style>
  </head>
  <body>
  <div class="wrap">
<h1><a href="">Ajax Image Upload with jQuery</a></h1>
<p>Valid formats: jpeg, gif, png, Max upload: 200kb</p>
<!-- loader.gif -->
<img style="display:none" id="loader" src="loader.gif" alt="Loading...." title="Loading...." />
<!-- simple file uploading form -->
<form id="form" action="ajaxupload.php" method="post" enctype="multipart/form-data">
    <input id="uploadImage" type="file" accept="image/*" name="image" />
    <input id="button" type="submit" value="Upload">
</form>
<!-- preview action or error msgs -->
<div id="preview" style="display:none"></div>
<p>&copy W3bees.com 2013</p>
   </div><!--wrap-->
   </body>
   </html>

Ajax上传代码:

   <?php

   $valid_exts = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions
   $max_size = 2000000 * 1024; // max file size
   $path = 'uploads/'; // upload directory

   if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if( ! empty($_FILES['image']) ) {
    // get uploaded file extension
    $ext = strtolower(pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION));
    // looking for format and size validity
    if (in_array($ext, $valid_exts) AND $_FILES['image']['size'] < $max_size) {
        $path = $path . uniqid(). '.' .$ext;
        // move uploaded file from temp to uploads directory
        if (move_uploaded_file($_FILES['image']['tmp_name'], $path)) {
            echo "<img src='$path' />";
        }
    } else {
        echo 'Invalid file!';
    }
} else {
    echo 'File not uploaded!';
}
    } else {
echo 'Bad request!';
    }

    ?>


  wampserver version 2.4
  php.ini 5.4.12

  max_execution_time = 600000  
  max_input_time = 600000
  memory_limit = 1000M
  post_max_size = 750MB;
  upload_max_filesize = 750M;

1 个答案:

答案 0 :(得分:0)

检查你的phpinfo() 看到这部分:

Loaded Configuration File

就我而言

/etc/php5/apache2/php.ini   

并查看您是否正在编辑正确的php.ini文件 编辑重启apache后重新加载php.ini文件