affordit Posted June 22, 2013 Share Posted June 22, 2013 (edited) I have a script to split video files into chunks and and write each chunk to a separate file, and another one to reassemble the files.What I can't figure out is how to read the file 1 chunk at a time without uploading it, does anyone have any idea how this might be done, or at least point me in the right direction? // File to split $filename = ""; // Target folder. Splitted files will be stored here. Original file never gets touched. $targetfolder = 'uploads'; // File size in Mb per piece/split. // For a 200Mb file if piecesize=10 it will create twenty 10Mb files $piecesize = 10; // splitted file size in MB $buffer = 1024; $piece = 1048576*$piecesize; $current = 0; $splitnum = 1; if(!file_exists($targetfolder)) { if(mkdir($targetfolder, 0777)) { //echo "Created target folder $targetfolder".br(); } } if(!$handle = fopen($filename, "rb")) { die("Unable to open $filename for read! Make sure you edited filesplit.php correctly!".br()); } $base_filename = basename($filename); $piece_name = $targetfolder.'/'.$base_filename.'.'.str_pad($splitnum, 3, "0", STR_PAD_LEFT); if(!$fw = fopen($piece_name,"w")) { die("Unable to open $piece_name for write. Make sure target folder is writeable.".br()); } //echo "Splitting $base_filename into $piecesize Mb files ".br()."(last piece may be smaller in size)".br(); //echo "Writing $piece_name...".br(); while (!feof($handle) and $splitnum < 999) { if($current < $piece) { if($content = fread($handle, $buffer)) { if(fwrite($fw, $content)) { $current += $buffer; } else { die("filesplit.php is unable to write to target folder. Target folder may not have write permission! Try chmod +w target_folder".br()); } } } else { fclose($fw); $current = 0; $splitnum++; $piece_name = $targetfolder.'/'.$base_filename.'.'.str_pad($splitnum, 3, "0", STR_PAD_LEFT); //echo "Writing $piece_name...".br(); $fw = fopen($piece_name,"w"); } } fclose($fw); fclose($handle); //echo "Done! ".br(); exit; ?> Edited June 22, 2013 by affordit Quote Link to comment https://forums.phpfreaks.com/topic/279463-reading-a-file-without-uploading-it/ Share on other sites More sharing options...
Christian F. Posted June 22, 2013 Share Posted June 22, 2013 I don't see any uploading going on there, nor do I fully understand what you're looking to do. Mixing up your terminology a bit, perchance? Just in case you're wondering: Reading a file with PHP (from a client computer) without uploading it is impossible. That's like eating a bag of chips, without opening the bag. Since PHP runs on the server-side it cannot access the file, unless it is uploaded to the server by the client. Same way that you can put the chips in your mouth, without first opening the bag to get to them. Quote Link to comment https://forums.phpfreaks.com/topic/279463-reading-a-file-without-uploading-it/#findComment-1437429 Share on other sites More sharing options...
affordit Posted June 23, 2013 Author Share Posted June 23, 2013 (edited) I know that you can read a file in chunks with html 5 without uploading I was hoping that I could read the chunks and write them to a new file and reassemble them after. Edited June 23, 2013 by affordit Quote Link to comment https://forums.phpfreaks.com/topic/279463-reading-a-file-without-uploading-it/#findComment-1437491 Share on other sites More sharing options...
kicken Posted June 23, 2013 Share Posted June 23, 2013 That doesn't really make much sense. In order to get the file to the server, you have to upload it. Whether you do that as a single large file or 20 small files doesn't really make much difference. Splitting it and doing it separate would actually increase the overall upload size due to http overhead. Quote Link to comment https://forums.phpfreaks.com/topic/279463-reading-a-file-without-uploading-it/#findComment-1437497 Share on other sites More sharing options...
affordit Posted June 23, 2013 Author Share Posted June 23, 2013 the object is to get around the max upload set by php. Quote Link to comment https://forums.phpfreaks.com/topic/279463-reading-a-file-without-uploading-it/#findComment-1437501 Share on other sites More sharing options...
Csharp Posted June 23, 2013 Share Posted June 23, 2013 You can just change the maximum upload size in you rPHP.ini or during runtime http://stackoverflow.com/questions/2184513/php-change-the-maximum-upload-file-size Quote Link to comment https://forums.phpfreaks.com/topic/279463-reading-a-file-without-uploading-it/#findComment-1437502 Share on other sites More sharing options...
affordit Posted June 23, 2013 Author Share Posted June 23, 2013 Thanks Csharp I do not have access to the ini file and did know that I could change the settings at runtime, problem solved. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/279463-reading-a-file-without-uploading-it/#findComment-1437504 Share on other sites More sharing options...
Christian F. Posted June 23, 2013 Share Posted June 23, 2013 To quote the thread you linked to, Csharp: If you can't change your php.ini, you're out of luck. You cannot change these values at run-time; Quote Link to comment https://forums.phpfreaks.com/topic/279463-reading-a-file-without-uploading-it/#findComment-1437505 Share on other sites More sharing options...
Csharp Posted June 23, 2013 Share Posted June 23, 2013 To quote the thread you linked to, Csharp: Well, then you have to set it via .htaccess or php.ini Quote Link to comment https://forums.phpfreaks.com/topic/279463-reading-a-file-without-uploading-it/#findComment-1437510 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.