Page 1 of 1

Warning: Missing boundary in multipart/form-data POST data

Posted: Thu Jan 21, 2010 3:49 am
by Sindarin
I am trying to use JQuery and AJAX in order to upload a file,

PHP returns this warning:
Warning: Missing boundary in multipart/form-data POST data in Unknown on line 0
If I don't set the contentType parameter to "multipart/form-data" then the remove PHP script doesn't retrieve the filename at all

The AJAX request using JQuery

Code: Select all

 
$("#image-add").click(function(ev)
{
    var row_thumbnail= $("#row_thumbnail").attr("value");
    
    alert(row_thumbnail); //the filename returned ok
 
    $.ajax(
    {
        url: "admin-requests.php",
        type: "POST",
        cache: false,
        contentType: "multipart/form-data",
        data: "row_thumbnail="+ row_thumbnail,
        beforeSend: function(){
        //loading...
        },
        success: function(data){
            //success
        },
        error: function(){
            //error 
        }
    });
});
 
The PHP Script:

Code: Select all

$row_thumbnail = $_FILES['row_thumbnail'];
echo 'file='.$row_thumbnail;
exit;
(also tried $_FILES['row_thumbnail']['name'] )

Re: Warning: Missing boundary in multipart/form-data POST data

Posted: Thu Jan 21, 2010 4:44 am
by Eran
Unfortunately you can't upload files using AJAX. Alternative approaches include using an iframe or flash for asynchronous file uploads.

Re: Warning: Missing boundary in multipart/form-data POST data

Posted: Thu Jan 21, 2010 4:45 am
by requinix
As for the error,

You aren't sending multipart/form-data content so don't tell PHP that you are. That key=value&key=value format is application/x-www-form-urlencoded.

Re: Warning: Missing boundary in multipart/form-data POST data

Posted: Thu Jan 21, 2010 8:12 am
by Sindarin
Unfortunately you can't upload files using AJAX. Alternative approaches include using an iframe or flash for asynchronous file uploads.
I see, I found out jquery ajaxupload plugin which works.