怎么获取超过2G文件的大小

如何获取超过2G文件的大小
在文件大于50M的时候便给予提示:“请上传小于50M的文件”,用的stat函数,可是超过2G的文件返回的文件大小就是错误的了,有没有什么好的方法?

------解决方案--------------------
使用GetFileSize API函数,
HANDLE hFile=CreateFile(szFileName,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if(hFile!=NULL)
{
Size=GetFileSize(hFile,NULL);
}
CloseHandle(hFile)

当然,我这里GetFileSize返回的大小的高位传了NULL,如果你的文件很大,就需要高位了.
具体说时查看MSDN

还有另一种方式获得文件大小:
WIN32_FIND_DATA info={0};
HANDLE hFile=FindFirstFile(szFileName,&info);
if(hFile!=NULL)
{
fileSize=info.nFileSizeLow;

}
FindClose(hFile);
也差不多,都有区分文件大小的高,低位
------解决方案--------------------
D_FILE_OFFSET_BITS=64
------解决方案--------------------
GetFileSizeEx
stat64

------解决方案--------------------
GetFileSize返回的文件大小为 两个DWORD(注意参数中也有一个),也就是0xFFFFFFFF FFFFFFF这么多字节,是多少G,你可以自己算算. 是 17179869184 G


DWORD GetFileSize( 
HANDLE hFile, 
LPDWORD lpFileSizeHigh
); 
Parameters
hFile 
[in] Open handle of the file whose size is being returned. The handle must have been created with either GENERIC_READ or GENERIC_WRITE access to the file. 
lpFileSizeHigh 
[out] Pointer to the variable where the high-order word of the file size is returned. This parameter can be NULL if the application does not require the high-order word. 
Return Values
The low-order DWORD of the file size indicates success. If lpFileSizeHigh is not NULL, the function puts the high-order DWORD of the file size into the variable pointed to by that parameter. If lpFileSizeHigh is NULL, 0xFFFFFFFF indicates failure. To get extended error information, call GetLastError. 

If lpFileSizeHigh is not NULL, 0xFFFFFFFF indicates failure and GetLastError returns a value other than NO_ERROR. 

------解决方案--------------------
GetFileSizeEx GetFileAttributeEx
------解决方案--------------------
通过stat64或定义__USE_FILE_OFFSET64就可取得64位文件大小。
fedora 16 32bit
------解决方案--------------------
_telli64
------解决方案--------------------
要多用MSDN,那是真正的“高手”“大师”“好老师”!
------解决方案--------------------
GetFileSize
This function retrieves the size, in bytes, of the specified file. A remote application interface (RAPI) version of this function exists, and it is named CeGetFileSize. 

DWORD GetFileSize( 
HANDLE hFile, 
LPDWORD lpFileSizeHigh); 
Parameters
hFile 
[in] Open handle of the file whose size is being returned. The handle must have been created with either GENERIC_READ or GENERIC_WRITE access to the file. 
lpFileSizeHigh 
[out] Pointer to the variable where the high-order word of the file size is returned. This parameter can be NULL if the application does not require the high-order word. 
Return Values
The low-order DWORD of the file size indicates success. If lpFileSizeHigh is non-NULL, the function puts the high-order DWORD of the file size into the variable pointed to by that parameter. If lpFileSizeHigh is NULL, 0xFFFFFFFF indicates failure. To get extended error information, call GetLastError. 

If lpFileSizeHigh is non-NULL, 0xFFFFFFFF indicates failure and GetLastError returns a value other than NO_ERROR. 

Remarks
Note that if the return value is 0xFFFFFFFF and lpFileSizeHigh is non-NULL, an application must call GetLastError to determine whether the function has succeeded or failed. The following sample code illustrates this point: