The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 18, 2019, 10:32:02 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: viewing a gigantic text file in the cloud  (Read 1614 times)
Phaėton
Lifer
*****
Offline Offline

Posts: 555


⎝⏠⏝⏠⎠


View Profile
« on: July 13, 2010, 06:21:40 AM »

Okay i had this problem, i had a 1.5 gig sql dump and i downloaded it and couldnt find a text
editor that could read it..... took forever to download as well... and what if you want to just
work in the cloud , dont have access to vi or ssh command line and you want to browse through
a giant log file, etc.... well here is my very basic big cloud file viewer... just place it in the directory with
a big file, change the $file =  line to match your file and voila!  im thinking of making a split function later if i get bored...

Code:
<?php

  $file
='bigassfile.sql';
  echo 
$file.'<br><hr><br>';
  
$fp fopen($file'r');
  if (isset(
$_REQUEST["start"])){
    
$start=$_REQUEST["start"];
    
$chunksize=$_REQUEST["chunksize"];
  } else {
    
$start=0;
    
$chunksize=512;
  }
  
fseek($fp$start);
  
$data fread($fp$chunksize);
  echo 
'<textarea rows=20 cols=120 wrap off>'.$data.'</textarea><br><hr><br>';
  echo 
'<a href="fileview.php?start='.($start+$chunksize+1).'&chunksize='
  
.$chunksize.'">next '
  
.$chunksize.'</a>';  
  
fclose($fp);
?>

Logged

When I was your age we used to walk to the TV to change the channel....  _̴ı̴̴̡̡̡ ̡͌l̡̡̡ ̡͌l̡*̡̡ ̴̡ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ ̡ ̴̡ı̴̡̡
isthisthingon
Global Moderator
Lifer
*****
Offline Offline

Posts: 2879



View Profile
« Reply #1 on: July 15, 2010, 09:41:03 PM »

Nice - thanks Phaėton.
Logged

I would love to change the world, but they won't give me the source code.
herbacious
Journeyman
***
Offline Offline

Posts: 51


View Profile
« Reply #2 on: August 04, 2010, 02:25:22 PM »

yeah thats cool

generally use less on the command line for this kind of thing

any great ideas on how you could get some basic searching going on there as well - don't generally want to page through a zillion lines

I suppose just
while(!preg_match($pattern$data)){ 
$start+=512
fseek
($fp$start);
fread($fp$chunksize);
}

would do it
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #3 on: August 04, 2010, 05:34:54 PM »

Unless you pattern is split across the 512 line. You actually need to read 512 (for example) but seek only 512 - (sizeof potential pattern match + 1) or you'll miss a lot.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!