1

Hi i am using froala editor and i can manage to save the content inside my database now i am just trying to upload images to my server , but i have no luck so far my only output is "Something went wrong, try again" here is my code.

<body>
  <div id="editor"></div>
</body>

<script>


 $(function() {
    $('#editor').froalaEditor({
      // Set the image upload URL.
      imageUploadURL: 'save.php',

      imageUploadParams: {
        id: 'my_editor'
      }
    })
  });


</script>

On my save.php

// Allowed extentions.
    $allowedExts = array("gif", "jpeg", "jpg", "png");

    // Get filename.
    $temp = explode(".", $_FILES["my_editor"]["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["my_editor"]["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["my_editor"]["tmp_name"], getcwd() . "/upload_image/" . $name);

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

I am trying to save the uploaded files into a folder inside my server named as upload_image.

KaoriYui
  • 912
  • 1
  • 13
  • 43
  • Hi! Please paste the html section of the form. – NetVicious May 02 '17 at 10:54
  • Ok so the dependencies was the problem including the extension php_imagick.dll the problem now is i cannot add this on my php.ini i am using php version 5.6. – KaoriYui May 03 '17 at 01:55
  • Why you cannot add it to your php.ini? Hosting provider restriction? – NetVicious May 03 '17 at 07:37
  • This link is exactly what i am experiencing but instead of wamp i am using xammp http://stackoverflow.com/questions/2942523/step-by-step-instructions-for-installing-imagemagick-on-wamp – KaoriYui May 03 '17 at 08:20
  • Check the first answer of that post. Xampp and Wampp are nearly the same only changing the application used to control the processes. You should download the binaries for windows. – NetVicious May 03 '17 at 08:25
  • @KaoriYui could you make a screenshot of what you get into the Network tab of the developer tools in the browser console? – st3fan Jul 10 '17 at 08:13

0 Answers0