0

Iam looking for jquery php image upload exactly given in http://valums.com/ajax-upload/. i tried code given in the above site. but its not working . as iam newbie.. i tried below code.

<?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";
}
?>

this is my html code

<!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>
5
  • 1
    What does "not working" mean? Commented May 9, 2012 at 12:09
  • can we see your full html code please Commented May 9, 2012 at 12:09
  • And if you change the first line to $uploaddir = '/uploads/'; does that work? When using localhost you are access via (i guess) xampp, and the upload dir should also be using your xampp. Have you also tried looking at what the console returns? (with debug true on any errors are logged to console) Commented May 9, 2012 at 12:12
  • no errors showing in console only below line.................[uploader] xhr - server response received fileuploader.js:873 Commented May 9, 2012 at 12:57
  • file is uploading ..showing failed.. Commented May 9, 2012 at 13:00

1 Answer 1

1

in php change:

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

to

$uploaddir = 'server/uploads';

in javascript change:

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

to

action: 'server/upload.php',

if the php file you are running is in the ajax-upload folder.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.