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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度