0

私は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.' }
}
})
});    

解決策を見つけるためにあらゆる場所を探しましたが、問題はまだ解決されていません。助けてください。感謝します

4

2 に答える 2

1

これが機能するかどうかはわかりませんが、行に絶対URLを指定してみてください

$response->link = "{absolute_url_to_image}/images/" . $name;

それは私にとってはうまくいっています

于 2014-07-30T07:34:14.737 に答える