c + + CGI client read a large file uploads do not complete solution

2010-12-22  来源:本站原创  分类:CPP  人气:147 

Although getenv ("CONTENT_LENGTH") can then be used directly on the stdin fread ()
But in practice found that sometimes file read failure

Web search for a long time, and finally discovered that to use binary mode to read, rather than text mode ...

Before reading, set the binary mode with the following statement:

_setmode(_fileno(stdin),_O_BINARY);

After the reading, with the following statement set back to text mode:

_setmode(_fileno(stdin),_O_TEXT);

With binary mode and text mode differences:
Transfer from http://captain.blog.edu.cn/2006/512355.html
The Difference Between Binary and Text Files

When you access a file from within C or C + + you have a choice between treating the file as a binary file or as a text file.

C uses the fopen (file, mode) statement to open a file and the mode identifies whether you are opening the file to read, write, or append and also whether the file is to be opened in binary or text mode.

C + + opens a file by linking it to a stream so you don't specify whether the file is to be opened in binary or text mode on the open statement. Instead the method that you use to read and / or write to the file determines which mode you are using. If you use the <<operator to read from the file and the>> operator to write to the file then the file will be accessed in text mode. If instead you use the put () and get () or read () and write () functions then the file will be accessed in binary mode.

So what exactly is the difference between text and binary modes? Well the difference is that text files contain lines (or records) of text and each of these has an end-of-line marker automatically appended to the end of it whenever you indicate that you have reached the end of a line. There is an end of line at the end of the text written with the C fwrite () function or in C + + when you <<endl. Binary files are not broken up into separate lines or records so the end-of line marker is not written when writing to a binary file.

Reading from a text file or binary file is different too as a text file is automatically broken up into separate records as it read in based on the location of the end-of-line markers.

So what is this end-of-line marker? Well that depends on the operating system that you are using. The Apple Macintosh computers use a single carriage return as the end-of-line marker (x'0D ') while Unix based operating systems including Linux use a single line-feed character (x'0A '). Most PC based systems including DOS, all versions of windows, and OS / 2 use a carriage return / line feed combination (x'0D0A') as the end -of-line marker. C and C + + terminate strings with a low value character (x'00 ').

So what happens when we read from a text file is that the end-of-line character for the operating system that we are using gets converted into a low value end-of-string indicator and when we write to a file the appropriate end- of-line character (s) get written when we indicate the end of the line. This makes the reading and writing of text files much easier because the appropriate end-of-line markers are handled for us.

With a binary file none of these conversions take place. When we read a binary file the end-of-line characters for our operating system will be read into the string and treated no different than any other character. When we write to a binary file the only end-of-line markers that are written will be those that we code into the output ourselves and hence will be exactly as we code it regardless of the operating system that we are running on. This makes it much easier for us when the file does not contain straight text and the end-of-line marker does not separate lines of text but rather appears as part of the non-text data content of the file.

A binary file can contain text but the text that it contains is not considered to be broken up into a number of lines by the occurrence of end-of-line markers. A binary file may alternatively contain information that contains no text whatsoever. It is up to the program reading the file to make sense of the data contained in a binary file and convert it into something meaningful (eg. an image or a series of fixed length records).

相关文章
  • c + + CGI client read a large file uploads do not complete solution 2010-12-22

    Although getenv ("CONTENT_LENGTH") can then be used directly on the stdin fread () But in practice found that sometimes file read failure Web search for a long time, and finally discovered that to use binary mode to read, rather than text mode .

  • ASP.NET large file uploads 2011-03-16

    http://caifu.zol.com.cn/206/2067734.html http://flajaxianfileupload.codeplex.com/ http://blog.bodurov.com/how-to-use-flajaxian-fileuploader-video-basics/ http://slfileupload.codeplex.com/ http://www.cnblogs.com/daizhj/archive/2008/10/28/1321252.html

  • Rails related to large file upload 2010-07-29

    Ordinary mongel normal large file uploads, may encounter memory exhaustion, Rails service of the blockage of some programs following require 'net/ftp' Net::FTP.open('uploads.yoursite.com','username','password') {|ftp| ftp.login('username','password')

  • Large file upload related Rails 2010-07-29

    Ordinary mongel normal large file uploads, may encounter memory exhaustion, Rails service of the blockage of some programs following require 'net/ftp' Net::FTP.open('uploads.yoursite.com','username','password') {|ftp| ftp.login('username','password')

  • Django Ajax file uploads and progress display 2009-03-09

    At Django 1.0 version, the file upload to do a great deal of change, one of a very important point is the introduction of the concept Upload Handlers. Upload Handlers This is Django's Middleware and almost anything can be set in the settings.py file

  • Implementation of file uploads 2010-10-19

    Implementation of file uploads is the use of a common property of FileUpload control FileContent property: Get stream object, which points to use FileUpload control to upload files; FileName property: get the client to use FileUpload control to uploa

  • Struts2 file uploads deal with the problem in Chinese 2010-03-24

    Afternoon of the next Struts2 taking the time to get the file upload, the Chinese had never solve the problem Then struts.xml configured struts.i18n.encoding to GBK, but the Chinese still garbled, looking for a long time have not been resolved Night,

  • Carried out with large file copy split MappedByteBuffer 2010-05-02

    Objective: Sometimes with large file transfer U disk, U disk space is too small, write a small program can transfer files easily separated. Issue 1: The Buffer directly to the file (1G or more) greet the memory, not directly into physical memory. Sol

  • struts2 multiple file uploads 2010-10-25

    struts2 multiple file uploads and single file upload is basically the same, the code is as follows: package com.wkx.action; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.

  • php large file read operation 2011-04-04

    1. Directly from file function to handle Note: Due to file all the contents of one function is read into memory, and php in order to prevent some of the procedures written in relatively poor take up too much memory and cause the system memory, so tha

  • struts1 file uploads 2011-04-22

    In struts1 and 2, respectively, commons-fileupload component of the packaging, make the file upload operation more convenient. This article explains how to use struts1 upload files. Steps: Prepare jsp page 1 2, in the form jsp form to configure an Ac

  • View the file system supports large file format 2011-09-15

    newfs-o largefiles / dev/vg00/rlvo123 fstyp-v / dev/vg00/lvo123 vxfs version: 4 f_bsize: 8192 f_frsize: 1024 f_blocks: 4194304 f_bfree: 4192176 f_bavail: 3930165 f_files: 1048076 f_ffree: 1048044 f_favail: 1048044 f_fsid: 1073741834 f_basetype: vxfs

  • HTML5 File Uploads with jQuery 2011-12-11

    HTML5 File Uploads with jQuery 网站 : http://tutorialzine.com/2011/09/html5-file-upload-jquery-php/ 该插件可让你在支持 HTML5 的浏览器上实现拖放图片上传的功能. 授权协议: 未知 开发语言: PHP JavaScript 操作系统: 跨平台

  • iis Another program is using this file, process can not access "solution to the problem (turn) 2011-07-28

    1 \ "Another program is using this file, process can not access!." This is creating a new website using IIS error when prompted. See this error is really Zhangerheshang puzzled. Directory access? Must be on INETPUB directory? Remember that this

  • oracle lock data file can not identify the solution 2010-11-10

    Can not identify / lock data file Error is: SQL> startup ORACLE Routine has started . Total System Global Area 293601280 bytes Fixed Size 1290208 bytes Variable Size 209715232 bytes Database Buffers 75497472 bytes Redo Buffers 7098368 bytes Completed

  • NFS client to improve the operational performance of large file write 2010-03-31

    To install the NFS file system to write large files may cause the order to the NFS server's file transfer rate dropped significantly. In this case, you have to determine whether this case follow the steps to solve the problem. Suppose the system is r

  • Large file statistics. Processing (hash segmentation statistics) 2010-10-18

    A Url is a string, and the longer the string. Compared to preserving and have brought trouble. We do md5 Url mapping, map it to a 64-bit integer value. Now mostly using a 64-bit. Md5 128 bit when originally calculated, the general is to take the top

  • JAVA MD5 Authentication large file (change) 2010-03-29

    MD5 authentication from the web looking for large files can indeed verify the MD5 algorithm for large files, but when the bytes of memory to do the mapping when the number of bytes is greater than 690M if so, would be wrong to see Gao Ren suggested t

  • Dom4j by way of reading large file stream 2010-04-02

    This article Dom4J large XML file to read, and maintain a small memory footprint. XML does not need to apply to all content resides in memory, to handle some of the discarded part of the situation. public class Dom4jSaxReaderSimpleExample implements

  • swfupload_web choice for file uploads 2010-04-25

    swfupload What is this? SWFUpload is a client file upload tool, originally developed by the Vinterwebb.se it through the integration of Flash and JavaScript technologies WEB developers with a feature-rich and then go beyond the traditional <input typ