注册 登录
编程论坛 VFP论坛

自己的服务器,用vfp下载,有的文件可以下载,有的不能下载,应该不是权限的问题

sych 发布于 2023-11-12 09:14, 371 次点击
应该是和myfll里面的函数重名了,低级错误

FUNCTION URL_DOWNFILE
LPARAMETERS INTER_URL,LOCALFILE
ERASE (LocalFile)
DECLARE INTEGER InternetOpen IN wininet STRING, INTEGER, STRING, STRING, STRING
DECLARE INTEGER InternetOpenUrlW IN wininet INTEGER, STRING, STRING, INTEGER, INTEGER, INTEGER
DECLARE INTEGER HttpQueryInfo IN wininet INTEGER, INTEGER, STRING @, INTEGER @, INTEGER @
DECLARE INTEGER InternetReadFile IN wininet INTEGER, STRING @, INTEGER, INTEGER @
DECLARE INTEGER InternetCloseHandle IN wininet INTEGER
URL_OPEN = INTERNETOPEN("qm3d",1,CHR(0),CHR(0),0)
IF URL_OPEN = 0
    RETURN -1
ENDIF
URL_SESSION = INTERNETOPENURLw(URL_OPEN,STRCONV(INTER_URL+CHR(0),5),null,2,16,0)
IF URL_SESSION = 0
    = INTERNETCLOSEHANDLE(URL_OPEN)
    RETURN -2
ENDIF
URL_FOPEN = FCREATE(LOCALFILE)
IF URL_FOPEN = -1
    = INTERNETCLOSEHANDLE(URL_SESSION)
    = INTERNETCLOSEHANDLE(URL_OPEN)
    RETURN -3
ENDIF
URL_QUERYINFO = SPACE(32)
URL_QUERYINFOLEN = LEN(URL_QUERYINFO)
IF HTTPQUERYINFO(URL_SESSION,5,@URL_QUERYINFO,@URL_QUERYINFOLEN,0) = 1
    URL_FILESIZE = VAL(LEFT(URL_QUERYINFO,URL_QUERYINFOLEN))
ELSE
    URL_FILESIZE = -1
ENDIF
URL_SIZESUM = 0
URL_READBUFFER = REPLICATE(CHR(0),40960)
DO WHILE .T.
    URL_READBYE = 0
    IF INTERNETREADFILE(URL_SESSION,@URL_READBUFFER,40960,@URL_READBYE) = 1
        IF URL_READBYE = 0
            EXIT
        ELSE
            = FWRITE(URL_FOPEN,URL_READBUFFER,URL_READBYE)
        ENDIF
        URL_SIZESUM = URL_SIZESUM+URL_READBYE
        IF URL_FILESIZE = -1
            IF URL_SIZESUM > 0001048576
                WAIT WINDOW NOWAIT "正在下载 "+STR(URL_SIZESUM/0001048576,10,3)+"M……" AT sROWS()/2,SCOLS()/2-30
            ELSE
                WAIT WINDOW NOWAIT "正在下载 "+STR(URL_SIZESUM/1024)+"K……" AT sROWS()/2,SCOLS()/2-30
            ENDIF
        ELSE
            IF URL_SIZESUM > 0001048576
                WAIT WINDOW NOWAIT "正在下载 "+STR(URL_SIZESUM/0001048576,10,3)+"M "+STR(URL_SIZESUM/URL_FILESIZE*100,6,2)+"%……" AT sROWS()/2,SCOLS()/2-30
            ELSE
                WAIT WINDOW NOWAIT "正在下载 "+STR(URL_SIZESUM/1024)+"K "+STR(URL_SIZESUM/URL_FILESIZE*100,6,2)+"%……" AT sROWS()/2,SCOLS()/2-30
            ENDIF
        ENDIF
    ELSE
        EXIT
    ENDIF
ENDDO
WAIT CLEAR
= FCLOSE(URL_FOPEN)
= INTERNETCLOSEHANDLE(URL_SESSION)
= INTERNETCLOSEHANDLE(URL_OPEN)
RETURN URL_SIZESUM
ENDFUNC


[此贴子已经被作者于2023-11-12 12:43编辑过]

4 回复
#2
nbwww2023-11-12 11:42


[此贴子已经被作者于2023-11-12 11:50编辑过]

#3
wengjl2023-11-12 15:48
不能下载的文件有可能正被别的用户使用中......
#4
sych2023-11-13 10:08
谢谢,一切恢复正常了,上面的代码可以正常使用
#5
iswith2023-11-13 22:24
一切恢复正常了!找到原因了吗?试试我的DLL在下载时,若不可以,将错误捕捉出来,以便知道是啥问题。。。。
1