【问题标题】:jquery php image upload using http://valums.com/ajax-upload/jquery php 图片上传使用 http://valums.com/ajax-upload/
【发布时间】:2012-05-17 22:43:46
【问题描述】:

我正在寻找在http://valums.com/ajax-upload/ 中完全给出的jquery php 图片上传。 我尝试了上述网站中给出的代码。但它不工作。作为我的新手..我尝试了下面的代码。

<?php
$uploaddir = 'c:\xampp\htdocs\ajax-upload\server\uploads\';
$uploadfile = $uploaddir . basename($_FILES['file']['name']);

if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
  echo "success";
} else {
  // WARNING! DO NOT USE "FALSE" STRING AS A RESPONSE!
  // Otherwise onSubmit event will not be fired
  echo "error";
}
?>

这是我的html代码

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link href="fileuploader.css" rel="stylesheet" type="text/css">
    <style>
        body {font-size:13px; font-family:arial, sans-serif; width:700px; margin:100px auto;}
    </style>
</head>
<body>
    <p><a href="http://github.com/valums/file-uploader">Back to project page</a></p>

    <p>To upload a file, click on the button below. Drag-and-drop is supported in FF, Chrome.</p>
    <p>Progress-bar is supported in FF3.6+, Chrome6+, Safari4+</p>

    <div id="file-uploader-demo1">
        <noscript>
            <p>Please enable JavaScript to use file uploader.</p>
            <!-- or put a simple form for upload here -->
        </noscript>
    </div>

    <script src="fileuploader.js" type="text/javascript"></script>
    <script>
        function createUploader(){
            var uploader = new qq.FileUploader({
                element: document.getElementById('file-uploader-demo1'),
                action: '../server/upload.php',
                debug: true
            });
        }

        // in your app create uploader as soon as the DOM is ready
        // don't wait for the window to load
        window.onload = createUploader;
    </script>
</body>
</html>

【问题讨论】:

  • “不工作”是什么意思?
  • 我们可以看看你的完整html代码吗
  • 如果你把第一行改成 $uploaddir = '/uploads/';那样有用吗?使用 localhost 时,您可以通过(我猜)xampp 访问,并且上传目录也应该使用您的 xampp。您是否也尝试过查看控制台返回的内容? (任何错误的调试都记录到控制台)
  • 没有错误仅显示在控制台下面的行......[uploader] xhr - server response received fileuploader.js:873
  • 文件正在上传..显示失败..

标签: php jquery ajax image


【解决方案1】:

在php更改中:

$uploaddir = 'c:\xampp\htdocs\ajax-upload\server\uploads\';

$uploaddir = 'server/uploads';

在 javascript 中更改:

action: 'http://localhost/ajax-upload/server/upload.php',

action: 'server/upload.php',

如果你正在运行的 php 文件在 ajax-upload 文件夹中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-05
    • 2019-02-06
    • 2021-09-05
    • 1970-01-01
    相关资源
    最近更新 更多