我去了Froala Docs
,复制并编辑了脚本(有点),但不知何故它似乎不起作用,我什至没有得到回应。这是我的代码:
upload.php:
<?php
// Allowed extentions.
$allowedExts = array("gif", "jpeg", "jpg", "png");
// Get filename.
$temp = explode(".", $_FILES["file"]["name"]);
// Get extension.
$extension = end($temp);
// An image check is being done in the editor but it is best to
// check that again on the server side.
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& in_array($extension, $allowedExts)) {
// Generate new random name.
$name = sha1(microtime()) . "." . $extension;
// Save file in the uploads folder.
move_uploaded_file($_FILES["file"]["tmp_name"], getcwd() . "images/" . $name);
// Generate response.
$response = new StdClass;
$response->link = "images/" . $name;
echo stripslashes(json_encode($response));
}
?>
upload.js(包含在我的网站中):
$(function(){
$('#edit').editable({
// Set the image upload parameter.
imageUploadParam: 'file',
// Set the image upload URL.
imageUploadURL: '/upload.php',
// CORS. Only if needed.
crossDomain: false,
// Additional upload params.
imageUploadParams: {id: 'edit'},
// Set the image error callback.
imageErrorCallback: function (error) {
// Custom error message returned from the server.
if (error.code == 0) { error: 'My custom error message.' }
// Bad link.
else if (error.code == 1) { error: 'Bad link.' }
// No link in upload response.
else if (error.code == 2) { error: ' No link in upload response.' }
// Error during file upload.
else if (error.code == 3) { error: 'Error during file upload.' }
// Parsing response failed.
else if (error.code == 4) { error: 'Parsing response failed.' }
// Image too large.
else if (error.code == 5) { error: 'Image too large.' }
// Invalid image type.
else if (error.code == 6) { error: 'Invalid image type.' }
// Image can be uploaded only to same domain in IE 8 and IE 9.
else if (error.code == 7) { error: 'Image can be uploaded only to same domain in IE 8 and IE 9.' }
}
})
});
我到处寻找解决方案,但问题仍未解决,请帮助我,我很感激