douji3426 2012-07-20 08:48
浏览 53
已采纳

php文件上传返回文件和文件路径的有效性

I have a webpage that contains a form with several text fields and an optional file upload.

When the user clicks the submit button I do the following:

  • check if a file has been selected for upload
  • if so, upload the file
  • when the file has finished uploading, submit the other form data

My question is this. At the moment, my php server script checks the file as to whether or not it is valid. As of now, I have no way of knowing whether or not the file is valid before submitting the form data. I would like to be able to know that the file was uploaded, valid and also the path where the file was saved.

var xmlhttp=new XMLHttpRequest();
var formData = new FormData();
formData.append("thefile", file);   
xmlhttp.addEventListener("load", uploadComplete, false);
xmlhttp.open("POST","uploadfile.php",true);
xmlhttp.setRequestHeader("enctype", "multipart/form-data");
xmlhttp.send(formData);

.

 function uploadComplete(evt) {
    alert("image upload complete");
    submitForm();
 }

I basically want to send information from php that can be read from my function uploadComplete

  • 写回答

2条回答 默认 最新

  • doulifang5554 2012-07-20 08:53
    关注

    An easy way to do this is to make a echo in your PHP script, like this for example :

    echo json_encode({YOUR INFORMATIONS});
    

    After in uploadComplete json_decode the return and you will be able to use the informations directly in javascript.

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

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀