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

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失