我已经挣扎了两周才找到这些问题的答案而没有任何成功。我使用phpgrid.com的phpgrid,这个错误不会在离线时发生,但是当我上传到服务器时,这个问题就出现了。每次我填写带有上传图片字段的表单时,都会弹出此错误。
Bellow是我从chrome开发人员工具中复制的回复。
<!-- begin snippet: js hide: false -->
<!-- language: lang-js -->
<script>
//<![CDATA[
var lastSel;
var phpGrid_products;
jQuery(document).ready(function($){
phpGrid_products = jQuery("#products").jqGrid({
url:"/data.php?dt=json&gn=products",
datatype:"json",
mtype:"GET",
colNames:["product_id","Type","Serial number","Product name","Product specification","End user","Acceptance date","Warranty expire date","Latest Status","Photo"], colModel:[
{"name":"product_id","index":"product_id","hidden":true,"edittype":"text","editable":true,
"editoptions":{"size":"30"}, "editrules":{"edithidden":false,"required":false,"number":true}
},
{"name":"type","index":"type","hidden":false,"width":70,"edittype":"text","editable":true,
"editoptions":{"size":"30"},"editrules":{"edithidden":false,"required":false}
},
{"name":"serial_number","index":"serial_number","hidden":false,"width":100,"edittype":"text","editable":true,
"editoptions":{"size":"30"},"editrules":{"edithidden":false,"required":false}
},
{"name":"product","index":"product","hidden":false,"edittype":"text","editable":true,
"editoptions":{"size":"30"},"editrules":{"edithidden":false,"required":false}
},
{"name":"specification","index":"specification","hidden":true,"edittype":"textarea","editable":true,
"editoptions":{"cols":60,"rows":6,"size":60},"editrules":{"edithidden":true,"required":false}
},
{"name":"end_user","index":"end_user","hidden":false,"edittype":"text","editable":true,
"editoptions":{"size":"30"},"editrules":{"edithidden":false,"required":false}
},
{"name":"acceptance_date","index":"acceptance_date","hidden":false,"width":80,"edittype":"text","editable":true,
"editoptions":{
"dataInit":function(el){
$(el).datepicker({
changeMonth: true,
changeYear: true,
dateFormat:'yy-mm-dd'
});
},"size":"30"},
"editrules":{"edithidden":false,"required":false,"date":true}
},
{"name":"warranty_expire","index":"warranty_expire","hidden":false,"width":80,"edittype":"text","editable":true,
"editoptions":{
"dataInit":function(el){
$(el).datepicker({
changeMonth: true,
changeYear: true,
dateFormat:'yy-mm-dd'
});},"size":"30"},
"editrules":{"edithidden":false,"required":false,"date":true}
},
{"name":"status","index":"status","hidden":false,"width":60,"edittype":"select","editable":true,
"formatter":"select","stype":"select",
"searchoptions":{"sopt":["eq"],"value":":All;Closed:Closed;In progress:In progess;Pending:Pending"},
"editoptions":{"value":"Closed:Closed;In progress:In progess;Pending:Pending"},
"editrules":{"edithidden":false,"required":false}
},
{"name":"picture","index":"picture","hidden":false,"align":"center","edittype":"file","editable":true,
"formatter":imageFormatter,"unformat":imageUnformatter,
"editoptions":{"enctype":"multipart/form-data"},
"editrules":{"edithidden":false,"required":false}
}
],
pager: "#products_pager1",
rowNum:10,
rowList:[10,20,30,50,100],
sortname:"status",
sortorder:"Desc",
viewrecords:true,
multiselect:false,
caption:"Product list and latest status",
altRows:true,
scrollOffset:22,
rownumbers:true,
shrinkToFit:true,
autowidth:true,
hiddengrid:false,
scroll:false,
height:"100%",
width:"1000",
sortable:true,
loadError:
function(xhr,status, err) {
try{
jQuery.jgrid.info_dialog(
jQuery.jgrid.errors.errcap,
"<div style=\"font-size:10px;text-align:left;width:300px;;height:150px;overflow:auto;color:red;\">"+ xhr.responseText +"</div>",
jQuery.jgrid.edit.bClose,{buttonalign:"center"
});
}
catch(e) { alert(xhr.responseText)};
},
gridview:true,
editurl:"/edit.php?dt=json&gn=products",
ondblClickRow: function(){
var row_id = $(this).getGridParam("selrow");
$(this).jqGrid("editGridRow", row_id, {
// --------- edit options ---------
afterShowForm:function(form_id){
var grid = $(this);
var row_id = grid.getGridParam("selrow");
var file_name = grid.jqGrid("getCell",row_id,"picture");
if(file_name=="" || file_name === null){
$("#picture").show();
$("#_fileLink").text(file_name).hide();
$("#_btnFileDelete").hide();
}else{
$("#_fileLink").attr("href", "images/products/" + file_name).text(file_name).show();
$("#_btnFileDelete").show();
$("#picture").hide();
$("#_btnFileDelete").click(function(){
ajaxFileDelete(form_id, row_id);
// return true;
});
}
},
onInitializeForm:function(form_id){
$('<a href="" id="_fileLink" target="_new"></a>').insertAfter("#picture").hide();
$('<button id="_btnFileDelete">Delete</button>').insertAfter("#_fileLink").hide();
},
afterSubmit:function(d,a){
var grid = $(this);
var row_id = grid.getGridParam("selrow");
$("#_products_debug_ajaxresponse").html("<pre>"+d.responseText+"</pre>");
success:{
ajaxFileUploadEdit(d,a,row_id);
}
return true;
},
jqModal:true,
checkOnUpdate:false,
savekey: [true,13],
width:560,
height:"100%",
navkeys: [false,38,40],
checkOnSubmit : false,
reloadAfterSubmit:false,
resize:true,
closeOnEscape:true,
closeAfterEdit:true,bottominfo:"* required",
viewPagerButtons:true,
beforeShowForm: function(frm) { }
}); // editGridRow
}, // ondblClickRow
loadComplete: function(data){
if($("#products").getGridParam("reccount") != 0){
$.each(data.rows,function(i,item){
if (item.cell['8'] != null) {
if (item.cell[8].substr(-1)==="d") {
$("#" + item.id).css("color","#000000");
$("#" + item.id).removeClass("ui-widget-content");
$("#" + item.id).css("background-color","#ffffff");
}
}if (item.cell['8'] != null) {
if (item.cell[8].substr(-1)==="s") {
$("#" + item.id).css("color","#000000");
$("#" + item.id).removeClass("ui-widget-content");
$("#" + item.id).css("background-color","#FF3232");
}
}if (item.cell['8'] != null) {
if (item.cell[8].substr(-1)==="g") {
$("#" + item.id).css("color","#000000");
$("#" + item.id).removeClass("ui-widget-content");
$("#" + item.id).css("background-color","#FFFF80");
}
}
})
};
},
loadtext:"Loading phpGrid ..."
});
jQuery("#products").jqGrid("navGrid", "#products_pager1",
{edit:true,add:true,del:true,view:true,cloneToTop:true,search:false,excel:false},
{
// --------- edit options ---------
afterSubmit:
function(d,a){
var grid = $(this);
var row_id = grid.getGridParam("selrow");
$("#_products_debug_ajaxresponse").html("<pre>"+d.responseText+"</pre>");
success:{ajaxFileUploadEdit(d,a,row_id);}
return true;
}, // icon edit options
afterShowForm:function(form_id){
var grid = $(this);
var row_id = grid.getGridParam("selrow");
var file_name = grid.jqGrid("getCell",row_id,"picture");
if(file_name=="" || file_name === null){
$("#picture").show();
$("#_fileLink").text(file_name).hide();
$("#_btnFileDelete").hide();
}else{
$("#_fileLink").attr("href", "images/products/" + file_name).text(file_name).show();
$("#_btnFileDelete").show();
$("#picture").hide();
$("#_btnFileDelete").click(function(){
ajaxFileDelete(form_id, row_id);
// return true;
});
}
},
onInitializeForm:function(form_id){
$('<a href="" id="_fileLink" target="_new"></a>').insertAfter("#picture").hide();
$('<button id="_btnFileDelete">Delete</button>').insertAfter("#_fileLink").hide();
},
afterSubmit:function(d,a){
var grid = $(this);
var row_id = grid.getGridParam("selrow");
$("#_products_debug_ajaxresponse").html("<pre>"+d.responseText+"</pre>");
success:{
ajaxFileUploadEdit(d,a,row_id);
}
return true;
},
jqModal:true,
checkOnUpdate:false,
savekey: [true,13],
width:560,
height:"100%",
navkeys: [false,38,40],
checkOnSubmit : false,
reloadAfterSubmit:false,
resize:true,
closeOnEscape:true,
closeAfterEdit:true,
bottominfo:"* required",
viewPagerButtons:true,
beforeShowForm: function(frm) { }
},
{
// --------- add options ---------
closeAfterAdd:true,
bottominfo:"* required",
viewPagerButtons:true,
afterComplete: function(response, postdata, formid) {
// auto reload
var $self = $(this);
setTimeout(function () {
$self.trigger("reloadGrid");
}, 50);
},
beforeShowForm: function(frm) {
},
afterSubmit:function(d,a){
success:{
ajaxFileUploadAdd(d,a);
}
return true;
},
afterShowForm:function(form_id){
var grid = $(this);
var row_id = grid.getGridParam("selrow");
var file_name = grid.jqGrid("getCell",row_id,"picture");
if(file_name=="" || file_name === null){
$("#picture").show();
$("#_fileLink").text(file_name).hide();
$("#_btnFileDelete").hide();
}else{
$("#_fileLink").attr("href", "images/products/" + file_name).text(file_name).show();
$("#_btnFileDelete").show();
$("#picture").hide();
$("#_btnFileDelete").click(function(){
ajaxFileDelete(form_id, row_id);
// return true;
});
}
},
onInitializeForm:function(form_id){
$('<a href="" id="_fileLink" target="_new"></a>').insertAfter("#picture").hide();
$('<button id="_btnFileDelete">Delete</button>').insertAfter("#_fileLink").hide();
},
afterSubmit:function(d,a){
var grid = $(this);
var row_id = grid.getGridParam("selrow");
$("#_products_debug_ajaxresponse").html("<pre>"+d.responseText+"</pre>");
success:{
ajaxFileUploadEdit(d,a,row_id);
}
return true;
},
jqModal:true,
checkOnUpdate:false,
savekey: [true,13],
width:560,
height:"100%",
navkeys: [false,38,40],
checkOnSubmit : false,
reloadAfterSubmit:false,
resize:true,
closeOnEscape:true,
closeAfterEdit:true,
bottominfo:"* required",
viewPagerButtons:true
},
{
// --------- del options ---------
reloadAfterSubmit:false,
jqModal:false,
bottominfo:"* required",
closeOnEscape:true
},
{
// --------- view options ---------
navkeys: [false,38,40],
height:250,
jqModal:false,
resize:true,
closeOnEscape:true
},
{closeOnEscape:true} // search options
);
jQuery("#products").jqGrid("navButtonAdd","#products_pager1",
{caption:"",title:"Toggle inline search", buttonicon :"ui-icon-search",
onClickButton:function(){
phpGrid_products[0].toggleToolbar();
}
}
);
jQuery("#products").jqGrid("filterToolbar", {searchOnEnter: false, stringResult: true, defaultSearch: "cn"});
phpGrid_products[0].toggleToolbar();
});
function getSelRows(){
var rows = jQuery("#products").jqGrid("getGridParam","selarrrow");
return rows;
}
// cellValue - the original value of the cell
// options - as set of options, e.g
// options.rowId - the primary key of the row
// options.colModel - colModel of the column
// rowObject - array of cell data for the row, so you can access other cells in the row if needed
function imageFormatter(cellValue, options, rowObject){
// Tambahan path folder untuk images karena di master detail tidak berfungsi
return (cellValue == "" || cellValue === null)?
"":"<img src=\""+ cellValue + "\" originalValue=\""+ cellValue +"\" title=\""+ cellValue +"\">";
}
// cellValue - the original value of the cell
// options - as set of options, e.g
// options.rowId - the primary key of the row
// options.colModel - colModel of the column
// cellObject - the HMTL of the cell (td) holding the actual value
function imageUnformatter(cellValue, options, cellObject){
return $(cellObject.html()).attr("originalValue");
}
function booleanFormatter(cellValue, options, rowObject){
var op;
op = $.extend({},options.colModel.formatoptions);
myCars=new Array();
//alert(op.No);
//mycars[cellValue]= op.boolean.No;
//mycars[cellValue]= op.boolean.Yes;
myCars[op.No]="No";
myCars[op.Yes]="Yes";
//alert(options[boolean]);
return myCars[cellValue];
}
function booleanUnformatter(cellValue, options, cellObject){
var op;
op = $.extend({},options.colModel.formatoptions);
//alert(op.No);
if(cellValue=="No")
return (op.No);
else
return (op.Yes);
//alert(op.boolean.Yes)
//return (op.boolean.cellValue);
// myCars=new Array();
// myCars["No"]='0';
// myCars["Yes"]=1;
//alert(myCars[cellValue]);
//alert(options.colModel.formatoptions[1]);
//return myCars[cellValue];
}
function ajaxFileUploadEdit(response, postdata, row_id) {
if ($("#picture").val() == ""){
return false;
}
ajaxFileUpload(row_id, "edit");
}
// parse json returend from edit.php for auto generated key, if cannot find, use non-autogen primary key instead
// auto generated key is probably not 100% reliable
function ajaxFileUploadAdd(response, postdata) {
obj= jQuery.parseJSON(response.responseText);
new_row_id = obj.id;
if(new_row_id == "" || new_row_id == 0){
new_row_id = postdata.product_id;
}
ajaxFileUpload(new_row_id, "add");
}
// file upload function used only during add
function ajaxFileUpload(row_id, oper){
$.ajaxFileUpload({
url: "/ajaxfileupload.php?dt=json&gn=products&oper=" +oper+ "&col=picture&folder=",
secureuri: false,
fileElementId: "picture",
dataType: "json",
data: { id: row_id },
success: function (data, status) {
$("#products").trigger("reloadGrid", [{current:true}]);
// displayCrudServerErr(xhr);
// does not capture responseText - TODO - needs new ajaxfileupload lib
if (typeof (data.error) != "undefined") {
if (data.error != "") {
alert(data.error);
} else {
return true;
}
}else {
return alert("Failed to upload!");
}
},
error: function (data, status, e) {
alert(e);
}
})
}
function ajaxFileDelete(form_id, row_id) {
$.ajax({
url: "/ajaxfiledelete.php?dt=json&gn=products&col=picture&folder=",
type: "POST",
data: {id: row_id, file_col: "picture"},
cache: false,
success: function (data, status) {
$("#products").trigger("reloadGrid", [{current:true}]);
$("#_fileLink").hide();
$("#_btnFileDelete").hide();
$("#picture").show();
$("#_products_debug_ajaxresponse").append("<pre>"+data +"</pre>");
}
})
}
//]]>
</script>
答案 0 :(得分:0)
您的实时服务器是否在Apache模块中安装了PHP?检查php.ini中的upload_tmp_dir。您可能需要set_col_fileupload中的第3个参数。
从 http://phpgrid.com/example/php-datagrid-ajax-file-upload/
由于PHP作为Apache模块安装在我们的主机服务器中,所以第3个 参数是可选的,物理路径是自动映射的 基于第二个参数,基本URL。
备注来自 http://phpgrid.com/documentation/set_col_fileupload/
仅在php.ini中具有有效upload_tmp_dir值的文件系统
文件名列应允许NULL值$ physical_path是自动获取的,如果PHP在Apache模块中运行,或者必须提供为 回退