dongtiao0657 2011-10-09 16:40
浏览 13
已采纳

jquery PHP图像上传(使用.post方法)

I am trying to upload images on a form but I am using Jquery .Post function in order to submit the data of the form. I get a PHP error of an undifined index. Here is a small portion of my code:

related HTML:

<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
Picture: <input name="uploadedfile" id="uploadedfile" type="file" />

related jQuery

    $.post("registerCB.php", {
    uploadedfile: $("#uploadedfile").val()
}

The PHP that handles the submission:

//file upload
        $uploadedfile= $_POST["uploadedfile"];



        /*--------------------Image Uploads-------------------------*/
        // Where the file is going to be placed 
        $target_path = "userImages/";

        /* Add the original filename to our target path.  
        Result is "uploads/filename.extension" */
        $target_path = $target_path . basename( $_FILES[$uploadedfile]['name']); 

THE ERROR: enter image description here

CONCLUSION: I think the issue is the .val() on the image input. I did an alert on that element and it would only alert the file name NOT the entire path.

How can I get the entire path?

ONE MORE THING---- I would like to control the NAME of the file. So no matter what the user uploads I can control the name....is this possible?

THANKS!!!

  • 写回答

4条回答 默认 最新

  • dongxi3859 2011-10-09 16:45
    关注

    The browser does not include the full path for security reasons. And you can control the name of the file on the server.

    If you want to upload asyncronously you should look at some of the existing jquery plugins such as:

    http://www.uploadify.com/

    or

    http://www.phpletter.com/Demo/AjaxFileUpload-Demo/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?