PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingPHP 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:
  #1  
Old May 18th, 2002, 01:51 PM
clawdragos clawdragos is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2002
Posts: 5 clawdragos User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Upload and Download with PHP & MSSql

i have some problems with that operation

these are my steps:

First i put the uploaded file into the required table

PHP Code:
function clean($input$maxlength)
{
  
$input substr($input0$maxlength);
  
$input EscapeShellCmd($input);
  return (
$input);
}
$short clean($short500);
$userfile clean($userfile500);
       
$file fopen($userfile"r");
       
$fileContents fread($filefilesize($userfile));
       
$fileContents AddSlashes($fileContents);
$connection mssql_connect("localhost","Administrator","bubu");
$db mssql_select_db("OTTManagement"$connection) or die("Couldn't select database OTTManagement.");
     
$insertQuery "INSERT INTO files(f_name,f_file) VALUES ('$short',\"$fileContents\")";
     
$insertQuery_query mssql_query($insertQuery,$connection) or die ("Couldn't that file ");

     
$qqq="select id_file,f_name,f_file from files";
     
$qqq_qmssql_query($qqq,$connection);
     while(
$data = @ mssql_fetch_array($qqq_q)){
            
$id $data["id_file"];
            
$ee$data["f_file"];
            
$ff$data["f_name"];
            echo 
"<a href=\"get_file.php?id=$id\">$ff</a><br>";
     } 



After that i want to downlod that file like this :


getfile.php


PHP Code:
 $connection mssql_connect("localhost","Administrator","bubu");
$db mssql_select_db("OTTManagement"$connection) or die("Couldn't select database OTTManagement.");
$qqq="select f_name,f_file from files where id_file=$id";
$qqq_qmssql_query($qqq,$connection);
$data = @ mssql_fetch_array($qqq_q);
$fname=$data["f_name"];
header("Content-type: application/octet-stream\n");
header ("Content-Disposition: attachment; filename=$fname");
header("Cache-control: must-revalidate\n");
header("Content-Description: PHP Generated Data");
echo 
$data["f_file"]; 


but for example if i will upload a file with size of 108 the file that i will download will have 134, and is not the same file.(I've tried with a gif file )


What is wrong ?

ps. in my MSSQL table field f_file have data_type image

Reply With Quote
  #2  
Old May 18th, 2002, 09:11 PM
mytch mytch is offline
Dev Articles Novice (500 - 999 posts)
 
Join Date: Apr 2002
Location: Sydney, Australia
Posts: 588 mytch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Hi.
What scenario are you using this code in? I assume people upload files and then you call clean? Remember that for MS SQL, you need to replace ' with '' and not \', so the addslashes might be causing your errors...

Check this article: http://www.devarticles.com/art/1/68. It's about blobbing with PHP and MySQL, but has the same principles if you can get your head around MySQL.

Can you paste the code for how your using it too... and do you get any errors on the download file script?

Reply With Quote
  #3  
Old May 19th, 2002, 02:50 AM
clawdragos clawdragos is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2002
Posts: 5 clawdragos User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
after I read that article , my script is sitill not working

supose that my contents lok like this :

after i replace ' with "

i get an error for this text for example

but now is the " newest

on the ". And how i will get the initial form of the $file ?


what should i do ?



I think that my problem is on the format that i put on the table

Last edited by clawdragos : May 19th, 2002 at 02:53 AM.

Reply With Quote
  #4  
Old May 21st, 2002, 12:07 AM
clawdragos clawdragos is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2002
Posts: 5 clawdragos User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
no i don't get any errors on the download, the problem is that the content is different

so where is the problem ?


ho should I get rid of that '

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Upload and Download with PHP & MSSql


Developer Shed Advertisers and Affiliates


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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap