0

我正在寻找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>
4

1 回答 1

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 文件夹中。

于 2012-05-09T12:10:28.867 回答