2

i made one script from here but now i have problem with geting $_POST['file']

her is the crsipt

index.php

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="jquery.min.js" type="text/javascript"></script>
<script src="ajax.js" type="text/javascript"></script>
<style>
progress
{
    background-color:#FF0000;
    width:250px;
    min-height:2px;
    height:4px;
    border:none;
}
progress::-webkit-progress-bar-value, progress::-webkit-progress-value, progress::-moz-progress-bar, progress::progress-bar
{
    background-color:#0F0;
}
</style>
</head>

<body>
<form enctype="multipart/form-data" method="post">
    <input name="file" type="file" id="file" />
    <input type="button" value="Upload" />
</form>
<div id="prc"></div>%<br>
<progress value="0" min="0" max="100"></progress>
<div id="det"></div>
</body>
</html>

ajax.js

// JavaScript Document
$(function(){
    $(':file').change(function(){
        var file = this.files[0];
        name = file.name;
        size = file.size;
        type = file.type;
        $("#det").html("NAME: "+name+"<br/>SIZE: "+size+"<br/>TYPE: "+type);
        //your validation
    });

    $(':button').click(function(){
        var formData = new FormData($('form')[0]);
        $("#data").html(formData);
        $.ajax({
            url: 'upload.php',  //server script to process data
            type: 'POST',
            xhr: function() {  // custom xhr
                myXhr = $.ajaxSettings.xhr();
                if(myXhr.upload){ // check if upload property exists
                    myXhr.upload.addEventListener('progress',progressHandlingFunction, false); // for handling the progress of the upload
                }
                return myXhr;
            },
            //Ajax events
            //beforeSend: beforeSendHandler,
            success: function(html) {
                $("#mess").html(html);
            },
            error:function(html) {
                $("#mess").html(html);
            },
            enctype: 'multipart/form-data',
            // Form data
            data: formData,
            //Options to tell JQuery not to process data or worry about content-type
            cache: false,
            contentType: false,
            processData: false
        });
    });
    function progressHandlingFunction(e){
        if(e.lengthComputable){
            $('progress').attr({value:e.loaded,max:e.total});
            $('#prc').html(e.loaded);
        }
    }
});

and the "upload.php" script when im geting the error

<?php
if(isset($_POST['file'])){
    echo $_POST['file'];
}else{
    echo 'file is not set';
}
?>

the resoults

NAME: ALISON LIMERICK - Where love lives.mp3
SIZE: 16584832
TYPE: audio/mp3

> file is not set

the progresbarr is working well but in php something wrong

somebody help me??

2
  • Is not workin @dale $_FILES['file'] i tryed Commented Jul 16, 2012 at 15:32
  • @antyrat i cant get the file to upload.php Commented Jul 16, 2012 at 15:33

1 Answer 1

1

You need to use $_FILES when dealing with files uploaded using Post. You can find information about $_FILES here.

More information can be found about handling file uploads at this link

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

1 Comment

with this upload.php <?php echo $HTTP_POST_FILES['file']['name']; im getting this error [1]SCREAM: Error suppression ignored for [2]Notice: Undefined variable: HTTP_POST_FILES in Z:\WEBS\wwwhost1\upload.php on line 2 ?>

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.