标题:VFP 上传文件到WEB服务器
只看楼主
aroffice
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2011-9-23
得分:0 
回复 4楼 sam_jiang
还有上传时必须要引用原来页面中的那个值。
2022-11-29 13:16
sam_jiang
Rank: 8Rank: 8
等 级:贵宾
威 望:10
帖 子:542
专家分:781
注 册: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
帖 子:21
专家分:24
注 册: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: 3Rank: 3
等 级:论坛游侠
威 望:3
帖 子:154
专家分:101
注 册:2013-5-14
得分:0 
这就是我们以前搞的头文一体,实在看不下去,POSTDATA与header还分开写,不管是自己看还是维护都方便,CREATEBINARY(FILETOSTR("20221119202630ks.xls"))加个专二进制看看
2023-03-01 11:09



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-510704-1-1.html




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

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