MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old February 20th, 2004, 11:07 PM
blobbybot blobbybot is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 3 blobbybot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
storing ms documents in mysql & php problem

i'm having a problem viewing ms documents i store in a mysql db. i'm splitting the blobs into 64k chunks so one document may take up 50 rows. i don't know if the problem lies in my php code.

here's what i'm doing to split the file
PHP Code:
 $fp fopen(_PATH_"rb");
      while(!
feof($fp))
      {
       
$data .= fread($fpfilesize(_PATH_));
      }
      
fclose($fp);
  
      
$splits strlen($data)/65536;
      
$data addslashes($data); 
      
$data addcslashes($data"\0"); 
      for(
$i=0$splits>$i$i++){
          
$lim = ($i==0)?(0):((65536*$i)-2);
          
$cutdata substr($data$lim65536);
          
$seq=$i+1;
      
$SQL=" INSERT INTO "._DB_PREFIX_."file_storage SET ";
      
$SQL.=" xref = '".$_COOKIE[userid]."', ";
      
$SQL.=" file_xref = '$file_xref', ";
      
$SQL.=" groupid = '0', ";
      
$SQL.=" privs = 'Private', ";
      
$SQL.=" mime = '$mime', ";
      
$SQL.=" filename = '$file', ";
      
$SQL.=" data = '$cutdata', ";
      
$SQL.=" timestamp = '".time()."', ";
      
$SQL.=" seq = '".$seq."' ";
      
mysql_query($SQL);
      } 


image files seem to work fine when i retrieve them, pdfs lose their fonts sometimes, but all microsoft documents have errors. any clue?

Reply With Quote
  #2  
Old February 20th, 2004, 11:15 PM
blobbybot blobbybot is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 3 blobbybot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
here's how i'm displaying the document:

PHP Code:
function createfile($filename){
        
$SQL=" SELECT * FROM "._DB_PREFIX_."file_storage WHERE filename='$filename' ORDER BY seq ASC";
        
$ra=mysql_query($SQL);
            while(
$rb=mysql_fetch_array($ra)){
                
$data[data].=trim($rb[data]);
                
$data[mime]=$rb[mime];
            }
        
$data[data]=trim($data[data]);
        return (
strlen($data[data])>0)?($data):(FALSE);
    }
    
   
$file=createfile($filename);
   
             if(
strlen($file[mime])>0){
             
header("Content-Type: ".$file[mime]."\n");
             
header("Content-Length: ".strlen($file[data])."\n");
             
header("Content-Transfer-Encoding: binary\n");
             
header("Content-Disposition: inline; filename=$_GET[fp]\n");
             
//$file[data] = stripslashes($file[data]);
             
print($file[data]);
             exit;
             } else {
             
header("Content-Type: application/octet-stream\n");
             
header("Content-Disposition: attachment; filename=\"$file[filename]\"\n");
             
header("Content-Transfer-Encoding: binary\n");
             
header("Content-Length: ".strlen($file[data])."\n");
             print(
$file[data]);
             exit;
             } 

Reply With Quote
  #3  
Old February 23rd, 2004, 10:13 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
I'd guess your trim could cause problems and that you need also to add stripslashes(), since you're adding them when you insert the data. Why are you bothering splitting the files? Just stick 'em in a blob.
__________________
Please don't PM me asking for solutions outside the scope of a thread.
Keeping all responses in a thread stands to help others who come along later,
which is after all what this forum's all about.

Reply With Quote
  #4  
Old February 23rd, 2004, 02:50 PM
blobbybot blobbybot is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 3 blobbybot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by dhouston
I'd guess your trim could cause problems and that you need also to add stripslashes(), since you're adding them when you insert the data. Why are you bothering splitting the files? Just stick 'em in a blob.

i tried not slicing the file but files over 1mb seemed to not insert. they are insterting into blobs.

Reply With Quote
  #5  
Old February 24th, 2004, 07:04 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Another option is to store the files on the file system and keep a reference to them in the database. Did you have any luck removing trim() and adding stripslashes()?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > storing ms documents in mysql & php problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway