php.ini 中与文件上传相关的指令
file_uploads:控制是否允许文件上传 upload_tmp_dir: 上传文件的临时存放目录 upload_max_filesize: 上传文件的最大大小 post_max_size: POST数据的最大大小,应该大于 upload_max_filesize
文件上传过程可能出现的错误
UPLOAD_ERROR_OK(0): 上传成功 UPLOAD_ERR_INI_SIZE(1): 文件大小超过 upload_max_filesize UPLOAD_ERR_FORM_SIZE(2): 文件大小超过前端页面限制 UPLOAD_ERR_PARTIAL(3): 文件部分上传 UPLOAD_ERR_NO_FILE(4): 文件没有上传 UPLOAD_NO_TMP_DIR(5): 没有指定存放上传文件的临时目录 UPLOAD_ERR_CANT_WRITE(7): 写文件失败 UPLOAD_ERR_EXTENSION(8): PHP扩展停止文件上传进程
文件会话上传进度
要打开的 php.ini 指令: session.upload_progress.enabled: 开启或者关闭文件回话上传进度 session.upload_progress.cleanup: 上传完毕后清除SESSION中的文件上传进度数据 session.upload_progress.prefix: SESSION中键名的前缀,默认为 upload_progress session.upload_progress.name: 例如,值为 haha,那么如果上传文件表单中有<input type='hidden' name='haha' value='xixi'>,那么上传进度信息是 $_SESSION['upload_progress_xixi'] session.upload_progress.freq: 上传进度信息更新频率,以字节或者百分比为单位,默认为 1% session.upload_progress.min_freq: 上传进度信息更新时间间隔,默认为 1 秒 上传进度信息存储在$_SESSION中,如下: <?php $_SESSION["upload_progress_123"] = array( "start_time" => 1234567890, // The request time "content_length" => 57343257, // POST content length "bytes_processed" => 453489, // Amount of bytes received and processed "done" => false, // true when the POST handler has finished, successfully or not "files" => array( 0 => array( "field_name" => "file1", // Name of the <input/> field // The following 3 elements equals those in $_FILES "name" => "foo.avi", "tmp_name" => "/tmp/phpxxxxxx", "error" => 0, "done" => true, // True when the POST handler has finished handling this file "start_time" => 1234567890, // When this file has started to be processed "bytes_processed" => 57343250, // Amount of bytes received and processed for this file ), // An other file, not finished uploading, in the same request 1 => array( "field_name" => "file2", "name" => "bar.avi", "tmp_name" => NULL, "error" => 0, "done" => false, "start_time" => 1234567899, "bytes_processed" => 54554, ), ) );
PHP上传文件进度详细参考PHP中文文档,链接如下: