我有 Kendo UI Grid 和 inline 编辑和我的字段之一 (propertyLogo) 我使用 kendoUpload上传图像。使用 kendoUpload 函数 fileUploadEditor,我使用 saveUrl: "./image.php", 并将图像转换为 base64 格式以保存到数据库中.当我添加/编辑时,我设法成功更新所有字段,但 propertyLogo 字段除外,它返回 NULL 结果。我不知道我做错了哪一部分,但我无法将图像保存到数据库中。在这里,我将提供我的脚本。
我的数据源和网格
/****************/
/** DATASOURCE **/
/****************/
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: "./getPropertyMasterData.php",
type: "POST",
data: function() {
return {
method: "getPropertyMasterData",
}
}
},
update: {
url: "./getPropertyMasterData.php",
type: "POST",
data: function () {
console.log("I'm calling update!!");
return {
method: "editPropertyMasterData",
}
},
complete: function (e) {
$('#grid').data('kendoGrid').dataSource.read();
}
},
destroy: {
url: "./getPropertyMasterData.php",
type: "POST",
data: function () {
return {
method: "deletePropertyMasterData",
}
},
complete: function (e) {
$('#grid').data('kendoGrid').dataSource.read();
}
},
},
schema: {
model: {
id: "propertyID",
fields: {
propertyID: { editable: false, nullable: true }
active: { editable: false, nullable: false, defaultValue: 'y'},
propertyName: { editable: true,type: "string",validation: {required: {message: "Required"}} },
propertyLogo: { editable: true, type: "string",validation: {required: {message: "Required"}} },
propertyColor: { defaultValue: "#000", editable: true, validation: { required: {message: "Required"}} },
businessRegistrationNo: { editable: true,type: "string",validation: {required: {message: "Required"}} },
noOfRooms: { defaultValue: 1, editable: true,type: "number",validation: {min: 1, required: {message: "Required"}} }
}
}
},
pageSize: 25
}); // End of Kendo DataSource
/****************/
/** KENDO GRID **/
/****************/
var grid = $("#grid").kendoGrid({
dataSource: dataSource,
sortable: true,
editable: { mode: "inline" },
columns: [
{ field: "active", title:" ", filterable: false,
template: "# if (active=='y'){# <span class='k-icon ehors-status-active-icon'></span> #} else {# <span class='k-icon ehors-status-inactive-icon'></span> # }#"},
{ field: "propertyName", title:"Property Name", width: "80" },
{ field: "businessRegistrationNo", title:"Business Reg. No.", width: "80" },
{ field: "propertyLogo", title:"Logo", width: "80", editor: fileUploadEditor
,template: "<div class='propertyLogo'><a></a>#=propertyLogo#</div>" },
{ field: "propertyColor", title:"Color", width: "80px", editor : getColor, template: function(dataItem) {
return "<div style='background-color: " + dataItem.propertyColor + ";'> </div>";
}},
{ field: "noOfRooms", title:"No of Rooms", width: "80px", format: "", template: "<div class='unit'>#= noOfRooms#</div>" },
//Button Name
{ command: [{ name: "edit", text: {
edit: "Edit",
update: "Update",
cancel: "Cancel"} }
], title: "" }
],
save: onSave, // <-- checking duplicate error.
noRecords: {template: "No Records" }
}).data("kendoGrid"); //end of kendo grid
function fileUploadEditor(container, options) {
$('<input type="file" id="fileUpload" name="fileUpload" /> ')
.appendTo(container)
.kendoUpload({
multiple:false,
async: {
saveUrl: "./image.php",
autoUpload: true,
},
validation: {
allowedExtensions: [".jpg", ".png", ".jpeg"]
},
success: onSuccess, // just a console log to view progress
upload: onUpload, // just a console log to view progress
progress: onProgress // just a console log to view progress
});
}
我的 image.php
图像将转换为base64 并存储到hexString 变量中。一旦 getPropertyMasterData.php 被调用,它将获取 hexString 值。目前在这里我可以看到它成功返回了一个值。
<?php
$file = $_FILES['fileUpload'];
$fileName = $_FILES['fileUpload']['name'];
$fileTmpName = $_FILES['fileUpload']['tmp_name']; //directory location
$fileSize = $_FILES['fileUpload']['size'];
$fileError = $_FILES['fileUpload']['error']; //default 0 | 1 got error
$fileExt = explode('.', $fileName); //split file name to get ext name.
$fileActualExt = strtolower(end($fileExt)); //change to lowercase for the extension file
$allowed = array('jpg','jpeg','png');
if (!in_array($fileActualExt, $allowed)) {
return ['error' => 'You cannot upload files of this type!'];
}
if ($fileError !== 0) {
return ['error' => 'Error occur when upload file!'];
}
if ($fileSize > 500000) {
return ['error' => 'Your file size is too big!'];
}
$fileDestination = './uploads/' . $fileName;
move_uploaded_file($fileTmpName, $fileDestination);
$data = file_get_contents($fileTmpName);
return ['hexString' => base64_encode($data)];
?>
我的 getPropertyMasterData.php
据说 $uploadPayload['hexString'] 将从 image.php 中获取一个变量,但不知何故它会返回 NULL 结果。其他领域工作正常。
<?php
$propertyID = "1";
include($_SERVER['DOCUMENT_ROOT'] . '/TM.pdo.php');
$ehorsObj = new TM();
$ehorsObj->TM_CONNECT($propertyID);
$uploadPayload = require "image.php"; // READ FILE FROM image.php | Return NULL result
if (isset($uploadPayload['error'])) {
// echo $uploadPayload['error']);
/* do something in case of error */
}
$method = $_POST['method'];
switch ($method){
case "getPropertyMasterData" :
$method($ehorsObj);
break;
case "editPropertyMasterData" :
$method($ehorsObj, $uploadPayload['hexString']);
break;
default:
break;
}
/** READ **/
function getPropertyMasterData($ehorsObj) {
$getcheckbox = (isset($_POST['c1']) ? $_POST['c1'] : "all"); // by default select *
$sql = "SELECT * FROM tblAdmProperty ";
if ($getcheckbox == "true") {
$sql .= " WHERE active = 'y' ";
}
$sql .= " ORDER BY 2 ASC " ;
$array = array();
$GetResult = $ehorsObj->FetchData($sql, $ehorsObj->DEFAULT_PDO_CONNECTIONS);
while ($row = $GetResult->fetch()){
$array[] = $row;
}
header("Content-type: application/json");
$result = json_encode($array);
echo $result;
}
/** EDIT **/
function editPropertyMasterData($ehorsObj, $NewHexString) {
$propertyID = (isset($_POST['propertyID']) ? $_POST['propertyID'] : '');
$propertyName = (isset($_POST['propertyName']) ? $_POST['propertyName'] : '');
$propertyLogo = (isset($_POST['propertyLogo']) ? $_POST['propertyLogo'] : '');
$propertyColor = (isset($_POST['propertyColor']) ? $_POST['propertyColor'] : '');
$businessRegistrationNo = (isset($_POST['businessRegistrationNo']) ? $_POST['businessRegistrationNo'] : '');
$noOfRooms = (isset($_POST['noOfRooms']) ? $_POST['noOfRooms'] : '');
$active = (isset($_POST['active']) ? $_POST['active'] : '');
$sqlUpdate = " UPDATE tblAdmProperty
SET propertyName = '" . $propertyName . "',
propertyLogo = '" . $NewHexString . "',
propertyColor = '" . $propertyColor . "',
businessRegistrationNo = '" . $businessRegistrationNo . "',
noOfRooms = '" . $noOfRooms . "',
active = '" . $active . "'
WHERE propertyID = '" . $propertyID . "' ";
$ehorsObj->ExecuteData($sqlUpdate, $ehorsObj->DEFAULT_PDO_CONNECTIONS);
}
?>
如果我使用 cookie 或 session ,它会起作用,但我尽量避免使用它们。我希望我能提供一个明确的解释。
最佳答案
最后,我设法让它发挥作用。
首先,我创建一个隐藏的文本框 <input type="hidden" id='uploadedFile' data-bind="value: propertyLogo" />
修复了我的 fileUploadEditor功能并添加remove.php (选修的)。 onSucces事件将在 image.php 中获取服务器响应并插入我之前创建的文本框值。
function onSuccess(e) {
console.log(e.response);
/* push server respoonse to texbox */
$("#uploadedFile").val(e.response);
}
function fileUploadEditor(container, options){
$('<input type="file" id="propertyLogo" name="propertyLogo" /> ')
.appendTo(container)
.kendoUpload({
multiple:false,
async: {
saveUrl: "image.php",
removeUrl: "remove.php",
autoUpload: true,
},
validation: {
allowedExtensions: [".jpg", ".png", ".jpeg"]
},
success: onSuccess
});
$("<span class='k-invalid-msg' data-for='propertyLogo'></span>").appendTo(container);
}
base64 后, 它需要在 json format 中<?php
$fileParam = "propertyLogo";
$uploadRoot = "uploads/";
$files = $_FILES[$fileParam];
if (isset($files['name'])){
$error = $files['error'];
if ($error == UPLOAD_ERR_OK) {
$fileSize = $files['size'];
if ($fileSize < 500000) { //500000 = 500mb
$targetPath = $uploadRoot . basename($files["name"]);
$uploadedFile = $files["tmp_name"];
/* get a full paths */
$fullpath = getcwd();
$newTargetPath = $fullpath . '/' . $targetPath;
move_uploaded_file($uploadedFile, $newTargetPath);
/* convert data into base64 */
$data = file_get_contents($uploadedFile);
$hex_string = base64_encode($data);
header('Content-Type: application/json');
echo json_encode($hex_string);
} else {
echo "Your file size is too big! ";
}
} else {
echo "Error code " . $error;
}
}
// Return an empty string to signify success
echo "";
?>
<?php
$fileParam = "propertyLogo";
$uploadRoot = "uploads/";
$targetPath = $uploadRoot . basename($_POST["name"]);
unlink($targetPath);
echo "";
?>
save事件我添加这一行,基本上从文本框中获取值并设置到我的 propertyLogo领域save: function(e){ e.model.set("propertyLogo",$("#uploadedFile").val()); }
关于php - 使用 Kendo Upload 的 Kendo Grid 内联编辑返回空结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56829239/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
很好奇,就使用rubyonrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提
假设我做了一个模块如下:m=Module.newdoclassCendend三个问题:除了对m的引用之外,还有什么方法可以访问C和m中的其他内容?我可以在创建匿名模块后为其命名吗(就像我输入“module...”一样)?如何在使用完匿名模块后将其删除,使其定义的常量不再存在? 最佳答案 三个答案:是的,使用ObjectSpace.此代码使c引用你的类(class)C不引用m:c=nilObjectSpace.each_object{|obj|c=objif(Class===objandobj.name=~/::C$/)}当然这取决于
我正在尝试使用ruby和Savon来使用网络服务。测试服务为http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2require'rubygems'require'savon'client=Savon::Client.new"http://www.webservicex.net/stockquote.asmx?WSDL"client.get_quotedo|soap|soap.body={:symbol=>"AAPL"}end返回SOAP异常。检查soap信封,在我看来soap请求没有正确的命名空间。任何人都可以建议我
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h
我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib