2

I'm using XAMPP as the server and well i can't seem to upload the image like the documentation of the editor showed me... here is the link: http://editor.froala.com/server-integrations/php-image-upload

I already investigated about the problem and normaly they all say is the link that's not correct because you need to put the absolute url there , but even that doesn't seem to work.

Here is the code: JS

 $(document).ready(function(){

    $('textarea').editable({inlineMode: false, height:200, imageUploadURL: 'upload_image.php',  imageErrorCallback: function (data) {
     // Bad link.
    console.log(data);
}
});
  });

upload_image.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.
// Do not use $_FILES["file"]["type"] as it can be easily forged.
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $_FILES["file"]["tmp_name"]);

if ((($mime == "image/gif")
|| ($mime == "image/jpeg")
|| ($mime == "image/pjpeg")
|| ($mime == "image/x-png")
|| ($mime == "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"], "C:\ xampp\htdocs\Swaggy\img\ " . $name);

    // Generate response.

    $response = new StdClass;
    $response->link = "/swaggy/img/" . $name;
    echo stripslashes(json_encode($response));
}

When i try to upload an image he forms an img tag in the editor in base 64 and then dissapears. The debugger shows me that the file upload_image.php has a 200 status and the error that shows me from console is this : Object {code: 4, message: "Parsing response failed"}

Paweł Obrok
  • 22,568
  • 8
  • 74
  • 70
RazorEdge347
  • 23
  • 1
  • 4

1 Answers1

2

It looks there is a problem with the PHP from your server and the response can't be parsed. You should check with Firebug what is the response from the server when you try to upload an image. finfo_file function for instance is available only starting with PHP 5.3. If your version is older this is the problem most probably.

st3fan
  • 1,630
  • 14
  • 32
  • Yeah i finally found a way how to check a post from an ajax call in the debugger... Yeah you're right the function is undefined "Fatal error: Call to undefined function finfo_open()" The problem is my version of PHP is 5.5 ... Something i'm forgetting ? By the way thanks a bunch – RazorEdge347 Sep 30 '14 at 17:09
  • See http://stackoverflow.com/questions/3579072/php-fileinfo-is-undefined-function. It looks that you have to enable it manually on Windows. – st3fan Oct 01 '14 at 00:09
  • I resolved the problem before you gave me the link , and now it's working, Thanks for your attention and help – RazorEdge347 Oct 01 '14 at 11:50