Déterminer la taille d'un fichier de téléchargement
# 0000000611
ajouté le 09/06/2008 02:42:07 et modifié le 09/06/2008
consulté 8009 fois
Niveau
initié
Version(s) Foxpro : VFP 6.0
Description
Pour suivre un téléchargement à partir de 'progressbar' ou autres visualisations ,on a besoin de connaitre la taille du ficher à télécharger à l'avance.
Cela est obtenu avec des appels API windows détaillées dans le programme.
http://msdn.microsoft.com/en-us/library/ms906347.aspx..... pour toute info supplémentaire sur HttpQueryInfo.
Code source :
*Retourner la taille d'un fichier quelconque à télécharger en octets
yUrl="http://www.algerie-ancienne.com/livres/Sahara/1849egc.zip"&&URL de téléchargement dont on veut déterminer la taille
*lpszAgent [in] Pointer to a string variable that contains the name of the application or entity calling the Internet functions. *dwAccessType [in] Type of access required *lpszProxyName[in] Pointer to a string variable that contains the name of the proxy server(s) *lpszProxyBypass[in] Pointer to a string variable that contains an optional list of host names or IP addresses, or both, that should not be routed through the proxy when dwAccessType is set to INTERNET_OPEN_TYPE_PROXY *dwFlags[in] Unsigned long integer value that contains the flags that indicate various options affecting the behavior of the function *Return value: a valid handle that the application passes to subsequent Win32 Internet functions. If InternetOpen fails, it returns NULL *On exit do not forget to call the closing function -- InternetCloseHandle. ***************************** DECLAREINTEGER InternetOpenUrl IN wininet; INTEGER hInternet,; STRING lpszUrl,; STRING lpszHeaders,; INTEGER dwHeadersLength,; INTEGER dwFlags,; INTEGER dwContext *hInternet [in] HINTERNET handle to the current Internet session. The handle must have been returned by a previous call to InternetOpen. *lpszUrl [in] Pointer to a string variable that contains the URL to begin reading. *lpszHeaders [in] Pointer to a string variable that contains the headers to be sent to the HTTP server. *dwHeadersLength [in] Unsigned long integer value that contains the length, in TCHARs, of the additional headers. *dwFlags [in] Unsigned long integer value that contains the API flags. *dwContext [in] Pointer to an unsigned long integer value that contains the application-defined value. *Returns a valid handle to the FTP, Gopher, or HTTP URL if the connection is successfully established, or NULL if the connection fails. ********************************* DECLAREINTEGER InternetCloseHandle IN wininet INTEGER hInet * hInternet [in] Valid HINTERNET handle to be closed *Returns TRUE if the handle is successfully closed, or FALSE otherwise ***********************************
DECLAREINTEGER HttpQueryInfo IN wininet; INTEGER hRequest,; LONG dwInfoLevel,; STRING @ lpvBuffer,; LONG @ lpdwBufferLength,; LONG @ lpdwIndex *Retrieves header information associated with an HTTP request. *hRequest [in] Handle returned by HttpOpenRequest or InternetOpenUrl. *dwInfoLevel [in] Combination of an attribute to be retrieved and flags that modify the request. For a list of possible attribute and modifier values, see Query Info Flags. *lpvBuffer [in] Pointer to a buffer that receives the information. This parameter must not be NULL. *lpdwBufferLength [in] Pointer to a variable that contains the size of the data buffer, in bytes. *lpdwIndex [in, out] Pointer to a zero-based header index used to enumerate multiple headers with the same name.
*Source API http://www.news2news.com/vfp/ (Merci - PI les exemples sont payants sur ce site !)
Commentaires
le 06/07/2008, Gregory Adam a écrit : - Tu oublies de fermer yhRequest
- Si tu ajoutes HTTP_QUERY_FLAG_NUMBER a HttpQueryInfo() nBufLen sera 4 et nSize = ctobin(left(cBuf, m.nBufLen), '4rs')
le 06/07/2008, ybenam a écrit : Merci de ce feed back .Oui effectivement il faut ajouter =InternetCloseHandle(yhRequest) au niveau de =InternetCloseHandle(yHandle)
Pour ctobin(left(cBuf, m.nBufLen), '4rs') : cette fonction n'existe pas en VFP6.0 ou du moins elle ne fait pas la même syntaxe et transcrite ainsi elle renvoie une erreur.Votre syntaxe est valable pour les versions récentes>=7(A vérifier). CTOBIN(cExpression) tout court en vfp6.0 n'admet pas de second paramètre.
Le programme a été testé sur plusieurs cibles et marche très bien !
- Tu oublies de fermer yhRequest
- J'aurais mis: nSize = VAL(left(cBuf, m.nBufLen ))
- Si tu ajoutes HTTP_QUERY_FLAG_NUMBER a HttpQueryInfo()
nBufLen sera 4
et
nSize = ctobin(left(cBuf, m.nBufLen), '4rs')