php ajax files 空,php - Empty $_FILES while AJAX Uploading - Stack Overflow

I Have got the Following Problem:

I'm trying to Upload a File via a Form over Ajax

Here is the HTML File:

no status

The JavaScript File:

/**

* Created by Kenny on 12.04.2015.

*/

$(document).ready(function(){

$("#submitBtn").click(function(){

var filename = $("#file").serialize();

$.ajax({

processData: false, // tell jQuery not to process the data

contentType: false, // tell jQuery not to set contentType

url: "upload.php",

enctype: 'multipart/form-data',

data : {

file: filename

},

type : "POST",

success: function(data){

if(data != "fail")

$(".status").html("Upload is availible at: " + data);

else

$(".status").html("Upload failed.");

}

});

});

});

And last but not lately the PHP File that does the Magic (Not really atm)

/**

* Created by PhpStorm.

* User: Kenny

* Date: 12.04.2015

* Time: 23:55

*/

$uploaddir = '/many/upload/' . uniqid() . '/';

if(!file_exists($uploaddir)){

mkdir($uploaddir, 0777, true);

}

$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {

echo "http://use.hints.me/" . $uploaddir;

file_put_contents($uploaddir . "/index.php", "<?php Header('Location: " . basename($_FILES['userfile']['name']) . "'); ?>");

} else {

echo "fail";

}

?>

My Problem here is that I only get empty $_FILES in the PHP-File, the PHP File somehow works fine when i use a Standard POST form, but with Ajax it doesnt work at all.

Excuse my messy Code, it's just a Proof of Concept to a friend of mine and not at all used for Providing a serious File Upload site. I just want to get this working.

Things i checked here before:

check the php.ini File if the File Upload is enabled

added enctype="multipart/form-data" to the Form

added the MAX_FILE_SIZE tag to the Form

checked StackOverFlow all over

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值