file upload - storing each and every chunk of data php -
hello trying upload data server, requirement if uploaded content large file , if connection disconnected need upload same file stopped , not start again. can upload file server unable resume upload.. there other way can this?? following code.
resume.php
<?php $host = "localhost"; $db_uname = "root"; $db_pass=""; $db_name = "upload"; $cont=mysql_pconnect($host,$db_uname,$db_pass) or die("too many connection, please try later "); mysql_select_db($db_name); ob_clean(); if($_post['submit']) { define('chunk_size', 1024*1024); // size (in bytes) of tiles chunk // read file , display content chunk chunk function readfile_chunked($filename, $retbytes = true) { mysql_query("insert uploads(chunk) values('')") or die('insert query: ' . mysql_error()); $last = mysql_insert_id(); $file = '/tmp/'.$_files['file']['name']; // file saved after chunking $buffer = ''; $cnt =0; $handle = fopen($filename, 'rb'); $a=file_get_contents($filename); $sql=mysql_fetch_array(mysql_query("select chunk uploads id='26'")); $b= $sql['chunk']; if(strcmp($a,$b)==0) // check if file chunked in folder , database data same { echo "success"; } else { echo "failure"; } //exit; if ($handle === false) { return false; } while (!feof($handle)) { $buffer = fread($handle, chunk_size); // open file existing content $current = file_get_contents($file); // append new person file $current .= $buffer; // write contents file file_put_contents($file, $current); mysql_query("update uploads set chunk =concat(chunk,'".mysql_real_escape_string($buffer)."') id='$last'") or die('update query: ' . mysql_error()); ob_flush(); flush(); if ($retbytes) { $cnt += strlen($buffer); //echo $cnt; } } $status = fclose($handle); if ($retbytes && $status) { //echo $cnt; return $cnt; // return num. bytes delivered readfile() does. } return $status; } $filename = $_files['file']['tmp_name']; readfile_chunked($filename); } ?> <form action="resume.php" method="post" enctype="multipart/form-data"> <input type="file" name="file" size="50" /> <br /> <input type="submit" name="submit" value="upload file" /> </form>
i can make code work on localhost have issue using on server data not chunked , saved on server
you need read file string jquery, cut string pieces, , upload each piece separately.
Comments
Post a Comment