| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1782 人关注过本帖, 1 人收藏
标题:VFP 上传文件到WEB服务器
只看楼主 加入收藏
aroffice
Rank: 2
等 级:论坛游民
帖 子:56
专家分:20
注 册:2011-9-23
收藏
得分:0 
回复 4楼 sam_jiang
还有上传时必须要引用原来页面中的那个值。
2022-11-29 13:16
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:790
专家分:1170
注 册:2021-10-13
收藏
得分:0 
***uploadtest.html***
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程()</title>
</head>
<body>

<form action="upload_file.php" method="post" enctype="multipart/form-data">
    <label for="file">文件名:</label>
    <input type="file" name="file" id="file"/><br/>
    <input type="submit" name="submit" value="提交">
</form>
<iframe id="iframe" src="" style="display: none;"/></iframe>

</body>
</html>

***upload_file.php***
<?php
echo "uploaded file type:" . $_FILES["file"]["type"] . "<br />";
if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/bmp")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "application/pdf")
|| ($_FILES["file"]["type"] == "application/octet-stream") //rar file
|| ($_FILES["file"]["type"] == "application/zip"))
//&& ($_FILES["file"]["size"] < 102400000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("./upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],"./upload/" . $_FILES["file"]["name"]);

      echo "Stored in: " . "./upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file"  ."<br/>";

  echo "Return error Code: " . $_FILES["file"]["error"] . "<br />";
  }
?>
2022-12-04 12:05
plsword
Rank: 2
等 级:论坛游民
威 望:1
帖 子:22
专家分:27
注 册:2015-10-19
收藏
得分:0 
以下是引用aroffice在2022-11-20 11:19:29的发言:



我现在已经在前面做好了登录,现在不知道如何加入文件的二进制数据到上传信息中。

                    YMID1=STREXTRACT(POWINHTTP.RESPONSETEXT, [__VIEWSTATE" value="], [" />])
                    YMID2=STREXTRACT(POWINHTTP.RESPONSETEXT, [__EVENTVALIDATION" value="], [" />])
&&设定数据分隔
                    POSTFGF="----WebKitFormBoundarySSoR4BK8bRgIJUh0"

**重新构建POST数据
                    POSTDATA="--"+POSTFGF+CHR(13)
                    POSTDATA=POSTDATA+[Content-Disposition: form-data; name="__VIEWSTATE"]+CHR(13)+CHR(13)+ZHURL(YMID1)+CHR(13)
                    POSTDATA=POSTDATA+"--"+POSTFGF+CHR(13)
                    POSTDATA=POSTDATA+[Content-Disposition: form-data; name="__EVENTVALIDATION"]+CHR(13)+CHR(13)+ZHURL(YMID2)+CHR(13)
                    POSTDATA=POSTDATA+"--"+POSTFGF+CHR(13)
                    POSTDATA=POSTDATA+[Content-Disposition: form-data; name="ctl00$ContentPlaceHolder1$UpFile"; filename="]+[20221119202630ks.xls]+["]+CHR(13)&&文件名
                    POSTDATA=POSTDATA+[ Content-Type: application/vnd.ms-excel]+CHR(13)
                    POSTDATA=POSTDATA+FILETOSTR("20221119202630ks.xls")+CHR(13)&&加入文件的二进制数据
                    POSTDATA=POSTDATA+"--"+POSTFGF+CHR(13)
                    POSTDATA=POSTDATA+[Content-Disposition: form-data; name="ctl00$ContentPlaceHolder1$UploadBtn"]+CHR(13)+CHR(13)
                    POSTDATA=POSTDATA+"--"+POSTFGF+CHR(13)
                    STRTOFILE(POSTDATA,"POSTdata.TXT")

                    POWINHTTP.OPEN("POST", SURL, .F.)
                    POWINHTTP.SETREQUESTHEADER("Content-Type", "multipart/form-data; boundary="+POSTFGF)
*!*                                POWINHTTP.SETREQUESTHEADER ("Content-Length",LEN(POSTSTR))
                    POWINHTTP.SETREQUESTHEADER("Referer", SURLR )
                    POWINHTTP.SEND(POSTSTR)  && 提交表单进行登录

_________________
个人认为问题应该出在FILETOSTR上,form-data上传文件不能直接用FILETOSTR生成的字串因为涉及到二进制的问题,式着用一下CREATEBINARY(FILETOSTR("文件名"))试试
CREATEBINARY:将 Visual FoxPro 字符型数据转换为二进制字符型数据
2023-03-01 10:08
iswith
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:5
帖 子:454
专家分:611
注 册:2013-5-14
收藏
得分:0 
这就是我们以前搞的头文一体,实在看不下去,POSTDATA与header还分开写,不管是自己看还是维护都方便,CREATEBINARY(FILETOSTR("20221119202630ks.xls"))加个专二进制看看
2023-03-01 11:09
ljb8864
Rank: 2
等 级:论坛游民
帖 子:171
专家分:14
注 册:2023-6-4
收藏
得分:0 
CREATEBINARY(FILETOSTR没用
2023-06-04 19:40
快速回复:VFP 上传文件到WEB服务器
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.052533 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved