0

我已阅读 Froala 编辑器的文档:http: //editor.froala.com/server-integrations/php-image-upload

已阅读有关堆栈溢出的相同问题的文章,但尚未成功。问题在于 $response 变量,它将图像路径放在图像 src 参数中。到目前为止,froala 正在将图像放在服务器上的指定文件夹中(因此脚本可以工作)。问题是 froala 没有将路径放在图像源中,这样就不会添加图像。

这是我的图片上传脚本(工作得很好)

<?php
$fileName = $_FILES["image"]["name"];
$fileTmpLoc = $_FILES["image"]["tmp_name"];
$fileType = $_FILES["image"]["type"];
$fileSize = $_FILES["image"]["size"]; 
$fileErrorMsg = $_FILES["image"]["error"]; 
$kaboom = explode(".", $fileName); 
$fileExt = end($kaboom);
$fileName = time().rand().".".$fileExt;
if (!$fileTmpLoc) { 
 header('Location: ../announcments.php?aid=9');
     exit();
} else if($fileSize > 5242880) { 
    echo "ERROR: Your file was larger than 5 Megabytes in size.";
    unlink($fileTmpLoc); 
    exit();
} else if (!preg_match("/.(gif|jpg|png|JPG)$/i", $fileName) ) {
     echo "ERROR: Your image was not .gif, .jpg, or .png.";
     unlink($fileTmpLoc); 
     exit();
} else if ($fileErrorMsg == 1) { 
    echo "ERROR: An error occured while processing the file. Try again.";
    exit();
}
$moveResult = move_uploaded_file($fileTmpLoc, "../uploads/contentimg/$fileName");
if ($moveResult != true) {
    echo "ERROR: File not uploaded. Try again.";
    unlink($fileTmpLoc); 

    //This bit has been taken as example from froala website. 
    // Generate response.
        $response = new StdClass;
        $response->link = "/uploads/contentimg/" . $fileName;
        echo stripslashes(json_encode($response));
        //example from froala ends
    exit();
}

所以这一定是错误的,因为其他一切都有效:

// Generate response.
            $response = new StdClass;
            $response->link = "/uploads/contentimg/" . $fileName;
            echo stripslashes(json_encode($response));

请帮忙。

4

1 回答 1

0

保存图像时,会发出 POST 请求。响应将是这样的:{link: '/uploads/contentimg/file_name.jpg'}. 在您的情况下,您必须确保响应链接可以作为绝对路径在浏览器中访问。如果您在http://example.com/my/long/path上,图像将在http://example.com/uploads/contentimg/file_name.jpg上访问。

于 2014-09-30T08:58:39.990 回答