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

报告相同问题?

悬赏问题

  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条