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

报告相同问题?

悬赏问题

  • ¥60 求会做山景bo1048b2程序的 直播声卡用
  • ¥15 51单片机与数码管实现电子琴
  • ¥15 h3.6m 人类行为预测论文复现
  • ¥50 wordpress项目注册报失败刷新后其实是成功状态,请求排查原因
  • ¥20 linxu服务器僵尸进程不释放,代码如何修改?
  • ¥15 pycharm激活不成功
  • ¥40 如果update 一个列名为参数的value
  • ¥15 基于51单片机的水位检测系统设计中LCD1602一直不显示
  • ¥15 OCS2安装出现问题,请大家给点意见
  • ¥15 ros小车启动launch文件报错