无法理解这一点, HTML表单(输入文件)使用AJAX发送到PHP上传,然后在数据库中保存路径 - 这是代码在一分钟看的样子。
HTML:
<form action="" id="upppic" method="post" enctype="multipart/form-data">
<label for="ppic">Change Profile Picture</label>
<input type="file" name="ppic">
<input type="submit" value="Upload">
</form>
AJAX:
$(function() {
$("form#upppic").submit(function() {
$('#loading').show();
var userid = localStorage.userid;
var userid = 2;
//disable the default form submission
event.preventDefault();
//grab all form data
var formData = new FormData($(this)[0]);
$.ajax({
url: "http://www.url.com/page.php?uid="+ userid,
type: "POST", // Type of request to be send, called as method
data: formData,
dataType: "text",
cache: false,
contentType: false,
processData:false,
crossDomain:true,
success: function(data){
alert(data);
$('#loading').hide();},
error: function (data){
alert(data);
$('#loading').hide();}
});
return false;
});
});
PHP:
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type,x-prototype-version,x-requested-with');
$uid=(int)$_GET['uid'];
if($uid>1)
{
echo "got here";}
PHP暂时没什么(由于批量调试),但是当它运行当前文件&lt; = 53kb似乎上传确定并且我得到“到这里警报”。任何其他大小的文件只返回[object object],控制台日志说它无法连接“page.php ...”
PHP.INI文件(在Root中)
upload_max_filesize=100M
post_max_size=105M
max_execution_time=2000
max_input_time=2000
memory_limit=128M
答案 0 :(得分:0)
<强>解:强> 搞定了;正如Vove在评论中所说,我联系了我的服务提供商,它神秘地开始工作。代码是正确的。