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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

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

Post 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'] )
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

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

Post by Eran »

Unfortunately you can't upload files using AJAX. Alternative approaches include using an iframe or flash for asynchronous file uploads.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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.
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

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

Post 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.
Post Reply