胖鸭 2015-05-15 12:47 采纳率: 66.7%
浏览 303

Ajax图片上传403错误

I have summernote implemented on my site and am trying to use an ajax call to handle the image upload. the code I am using I have taken from another stackoverflow post and it works for other people and I have only changed the URLs. However i get the following error:

GET http://intranet-dev/Dev/Rehan/ProjectTracker/%3Cbr%20/%3E%3Cb%3EParse%20err…te_doc_upload_post.php%3C/b%3E%20on%20line%20%3Cb%3E23%3C/b%3E%3Cbr%20/%3E 403 (Forbidden)

summernote uses this:

        onImageUpload: function(files, editor, welEditable) {
        sendFile(files[0], editor, welEditable);
        }

and then the sendfile function makes the ajax call:

function sendFile(file, editor, welEditable) {
    data = new FormData();
    data.append("file", file);
            $.ajax({
                data: data,
                type: "POST",
                //url: "/Dev/Rehan/ProjectTracker/form_summernote_doc_upload_post.php",
                 url: "form_summernote_doc_upload_post.php",
                cache: false,
                contentType: false,
                processData: false,
                success: function(url) {
                    editor.insertImage(welEditable, url);
                }
            });
}

the php where it is posted to looks like this:

if ($_FILES['file']['name']) {
        if (!$_FILES['file']['error']) {
            $name = md5(rand(100, 200));
            $ext = explode('.', $_FILES['file']['name']);
            $filename = $name . '.' . $ext[1];
            $destination = '/uploads/document/summernote/' //change this directory
            $location = $_FILES["file"]["tmp_name"];
            move_uploaded_file($location, $destination);
            echo 'http://intranet-dev/Dev/Rehan/ProjectTracker/uploads/document/summernote/'.$filename;//change this URL

        }
        else
        {
          echo  $message = 'Ooops!  Your upload triggered the following error:  '.$_FILES['file']['error'];
        }
    }
  • 写回答

0条回答 默认 最新

    报告相同问题?