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 November 19th, 2002, 05:47 AM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
BLOB Tutorial - PHP

Has anyone managed to get this to work? I get it all to work except for the fact that everything (without fail) that I later try to download is corrupt.

Reply With Quote
  #2  
Old November 19th, 2002, 12:22 PM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Mitchell Harper where are you?

Reply With Quote
  #3  
Old November 19th, 2002, 06:33 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,240 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 18
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Kanu,

Would you mind posting the code. It will help us determine the problem... Also, are you declaring the file-type in your download script?
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Reply With Quote
  #4  
Old November 19th, 2002, 06:45 PM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Here it is (attached) - the support file I used. I had to change the name of a variable in one file since it was incorrectly calling blobId when the other file was expecting fileId to be called or vice versa, you'll spot that yourself. Also, as a side note, tonight I updated Apache to 2.0.43 (latest as of this time) and also updated PHP to 4.30.RC1 (latest as of this time) and still no change.

Any images I store as BLOBs come out as the dreaded Red Cross, zip files give me the "Try redownloading this archive" error in Winzip and PDF files get pretty much the same thing.


EDIT: Here is the URL of the original tutorial.
Attached Files
File Type: zip supportfile.zip (3.1 KB, 1158 views)

Last edited by Kanu : November 19th, 2002 at 06:49 PM.

Reply With Quote
  #5  
Old November 21st, 2002, 02:08 PM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Erm...?

Reply With Quote
  #6  
Old November 21st, 2002, 09:21 PM
strangepup's Avatar
strangepup strangepup is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2002
Location: Phoenix, AZ
Posts: 44 strangepup User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 46 sec
Reputation Power: 17
Send a message via ICQ to strangepup
yeah...i have never been able to get that tutorial to work.
i have been able to upload, but everything i view has garbage characters.
__________________
Web Solutions For Everyone @
Strangepup.com


Reply With Quote
  #7  
Old November 22nd, 2002, 07:22 AM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
So I'm not the only one... well, that may be a bit of comfort. Thing is, the owners of the site surely do, unless they were doctoring some pictures, though I doubt that.

Reply With Quote
  #8  
Old November 22nd, 2002, 05:26 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,240 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 18
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Kanu,

Do you receive any error messages at all?

I've been able to run the tutorial without any problems, which I find weird that you are having trouble.

Also, are you checking to make sure that the data is actually being stored in the database?

Also, check to see what your "register_globals" is set to. This script assumes they're set to on, which may be the source of your problem.

Reply With Quote
  #9  
Old November 22nd, 2002, 07:28 PM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Yeah, I *literally* use the code from the zip file (the only change being the necessary one to correct an error) and yeah, register_globals is on, as I run a copy of vBulletin from the same server. I can tell it's some stupid crap setting somewhere.

Reply With Quote
  #10  
Old November 24th, 2002, 11:38 AM
Gee Gee is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 61 Gee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
yeach,

I have terrible problems with this tutorials scripts. Dont work at all for me.

Even after setting global varialbles to On.

Warning: fopen("", "r") - No error in C:\FoxServ\www\grabfile.php on line 25

Warning: fread(): supplied argument is not a valid File-Handle resource in C:\FoxServ\www\grabfile.php on line 26

Maybe because I am using php4 and these scripts were designed for php3?

It sucks man.

Gee

Reply With Quote
  #11  
Old November 24th, 2002, 12:57 PM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Yup, sucks it does. You'd think that someone would know what was going wrong...

Reply With Quote
  #12  
Old November 24th, 2002, 01:41 PM
Gee Gee is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 61 Gee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
hey kanu,

Try this, it might solve your problem.

: On systems which differentiate between binary and text files (i.e. Windows) the file must be opened with 'b' included in fopen() mode parameter.


Example...

Insert "b" after the "r" in grabfiles.php as shown below.


$fileHandle = fopen($fileUpload, "rb");

Here is a link describing the process if needed

http://www.php.net/manual/en/function.fread.php

Let me know if u have any success! - Unfortunatly for me I cannot even get the files to upload properly in the first place!

Dammn fustrating when ure trying to learn a new technololgy and tutorials dont even work!

Gee - hElP !

Reply With Quote
  #13  
Old November 24th, 2002, 06:36 PM
Gee Gee is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 61 Gee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Hi there,

Is there anyone out there that could tell me as to why this script is not working properly?
Please - I am tearing my hair out as we speak.

The script first runs into problems at the if selection method (I keep getting the die result even when I have entered both the file name and a description. I have commented this out to try and test the rest of the code.

Second problem is that when I upload a file, I get a successful upload except that none of the file information is displayed back to the user as well as not being stored in the myBlobs table (the file is stored however).

I also get the following errors output: -

Warning: fopen("", "rb") - No error in C:\FoxServ\www\grabfile.php on line 30

Warning: fread(): supplied argument is not a valid File-Handle resource in C:\FoxServ\www\grabfile.php on line 31


Here is the code below - if you can spot anything I would be very, very grateful if you could let me know what the problem is.

I am using apache 2.0.39 (Win32) php/4.2.2

PHP Code:
// GrabFile.php: Takes the details
// of the new file posted as part
// of the form and adds it to the
// myBlobs table of our myFiles DB.

global $strDesc;
global 
$fileUpload;
global 
$fileUpload_name;
global 
$fileUpload_size;
global 
$fileUpload_type;

// Make sure both a description and
// file have been entered (not working properly)
//if(empty($strDesc) || $fileUpload == "none")
//  die("You must enter both a description and file");

// Database connection variables (put your uname, password here)
$dbServer "localhost";
$dbDatabase "myFiles";
$dbUser "your username";
$dbPass "your password";

$fileHandle fopen($fileUpload"rb");
$fileContent fread($fileHandle$fileUpload_size);
$fileContent addslashes($fileContent);

$sConn mysql_connect($dbServer$dbUser$dbPass)
  or die(
"Couldn't connect to database server");

$dConn mysql_select_db($dbDatabase$sConn)
  or die(
"Couldn't connect to database $dbDatabase");

$dbQuery  "INSERT INTO myBlobs VALUES ";
$dbQuery .= "(0, '$strDesc', '$fileContent', '$fileUpload_type')";

mysql_query($dbQuery) or die("Couldn't add file to database");

echo 
"<h1>File Uploaded</h1>";
echo 
"The details of the uploaded file are shown below:<br><br>";
echo 
"<b>File name:</b> $fileUpload_name <br>";
echo 
"<b>File type:</b> $fileUpload_type <br>";
echo 
"<b>File size:</b> $fileUpload_size <br>";
echo 
"<b>Uploaded to:</b> $fileUpload <br><br>";
echo 
"<a href='getfiles.php'>Add Another File</a>";

?> 

Gee

Last edited by Gee : November 26th, 2002 at 09:16 AM.

Reply With Quote
  #14  
Old November 26th, 2002, 04:33 AM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Bump.

Reply With Quote
  #15  
Old November 26th, 2002, 01:06 PM
patco patco is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 9 patco User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Blob Files No Problem

I have had no problem getting the files to work. The only problem I hve had is as follows.

1) If I try to right click on the "Download File" link and select save as... it always gives me the file name as download. Can this be changed to give the file a unique name like file 1 file2 etc

2) If I click on the "Download File" link it ipens the photo ona ne w window but I would like to add some text to this window like a "close Window" button but cannot work out where to insert the code.

Can anyone help and in turmn I will help them to get their scripts working.

Reply With Quote
  #16  
Old November 26th, 2002, 02:22 PM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Well, for the second part as far as I'm aware... all you'd need is something in the download.php that checked the header filetype and shaped the download appropriately.

eg:

PHP Code:
if (filetype==imagefiletype)
{
additional code to show closewindow here;
}
else
{
normal download code here;


Reply With Quote
  #17  
Old November 26th, 2002, 02:43 PM
patco patco is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 9 patco User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Tried that. Does not work.

I tried that but it does not seem to work. The code for the download file is as follows:

<?php

global $blobId;

if(!is_numeric($blobId))
die("Invalid blobId specified");

// Database connection variables
$dbServer = "localhost";
$dbDatabase = "mydatabase";
$dbUser = "myuser";
$dbPass = "mupass";

$sConn = mysql_connect($dbServer, $dbUser, $dbPass)
or die("Couldn't connect to database server");

$dConn = mysql_select_db($dbDatabase, $sConn)
or die("Couldn't connect to database $dbDatabase");

$dbQuery = "SELECT blobType, blobData ";
$dbQuery .= "FROM myBlobs ";
$dbQuery .= "WHERE blobId = $blobId";

$result = mysql_query($dbQuery) or die("Couldn't get file list");

if(mysql_num_rows($result) == 1)
{
$fileType = @mysql_result($result, 0, "blobType");
$fileContent = @mysql_result($result, 0, "blobData");

header("Content-type: $fileType");
echo $fileContent;
echo "BACK";
}
else
{
echo "Record doesn't exist.";
}

?>

Where can I enter additional HTM?

Reply With Quote
  #18  
Old November 26th, 2002, 03:36 PM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Quote:
Originally posted by Gee
hey kanu,

Try this, it might solve your problem.

: On systems which differentiate between binary and text files (i.e. Windows) the file must be opened with 'b' included in fopen() mode parameter.


Example...

Insert "b" after the "r" in grabfiles.php as shown below.


$fileHandle = fopen($fileUpload, "rb");

Here is a link describing the process if needed

http://www.php.net/manual/en/function.fread.php

Let me know if u have any success! - Unfortunatly for me I cannot even get the files to upload properly in the first place!

Dammn fustrating when ure trying to learn a new technololgy and tutorials dont even work!

Gee - hElP !
Yup, that works fantastic.

Reply With Quote
  #19  
Old November 26th, 2002, 03:40 PM
patco patco is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 9 patco User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I dont think so

I dont think that will work. I am on a unix server.

i got the files to upload fine. What was your problem?

Can I help?

Reply With Quote
  #20  
Old November 26th, 2002, 06:00 PM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
I edited the fopen() parameters to specify that the file was to be read as binary. That worked. I think all previos corruption must have been when the Binary info was being input into the database as ASCII.

Reply With Quote
  #21  
Old November 26th, 2002, 06:07 PM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Re: Tried that. Does not work.

Quote:
Originally posted by patco
I tried that but it does not seem to work. The code for the download file is as follows:

PHP Code:
global $blobId;
    
if(!
is_numeric($blobId))
    die(
"Invalid blobId specified");

// Database connection variables
$dbServer "localhost";
$dbDatabase "mydatabase";
$dbUser "myuser";
$dbPass "mupass";
    
$sConn mysql_connect($dbServer$dbUser$dbPass)
  or die(
"Couldn't connect to database server");
      
$dConn mysql_select_db($dbDatabase$sConn)
  or die(
"Couldn't connect to database $dbDatabase");
      
$dbQuery  "SELECT blobType, blobData ";
$dbQuery .= "FROM myBlobs ";
$dbQuery .= "WHERE blobId = $blobId";

$result mysql_query($dbQuery) or die("Couldn't get file list");
    
if(
mysql_num_rows($result) == 1)
{
    
$fileType = @mysql_result($result0"blobType");
    
$fileContent = @mysql_result($result0"blobData");
        
    
header("Content-type: $fileType"); 
    echo 
$fileContent
    echo 
"BACK";
}
else
{
    echo 
"Record doesn't exist.";



Where can I enter additional HTM?



I would imagine something like -

PHP Code:
 $result mysql_query($dbQuery) or die("Couldn't get file list");
    
if(
mysql_num_rows($result) == 1)
{
    
$fileType = @mysql_result($result0"blobType");
    
$fileContent = @mysql_result($result0"blobData");
        
    
header("Content-type: $fileType"); 
    echo 
$fileContent
    echo 
"BACK";
}
if (
$fileType=="image/jpeg")
{
echo 
the HTML here
}
else
{
    echo 
"Record doesn't exist.";


Reply With Quote
  #22  
Old November 27th, 2002, 12:44 AM
patco patco is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 9 patco User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Nothing doing

I tried your suggestion but it still does not work.

I think it has to do with the statement:

header("Content-type: $fileType");
echo $fileContent;

This is what sdisplays the photo on the screen. I tried placing the php code ina regular html page but got an error message saying that headears were already declared. If it was possible to remove or re position this statement I think it might work fine.

Any ideas?

Reply With Quote
  #23  
Old November 27th, 2002, 10:35 AM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
How about using the if/else loops to redirect to another page depending on what the $filetype variable is?

Reply With Quote
  #24  
Old November 27th, 2002, 10:48 AM
patco patco is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 9 patco User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
THe file type is not the problem

The file type is not the problem. I am only using jpg photos.

The problem is that in addition to displaying the photo I cannot display any other text like as I said a "Close Wondow2 button or maybe a description taken from another field of the database.

Reply With Quote
  #25  
Old November 27th, 2002, 03:02 PM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
No, I meant something like this:

PHP Code:
 $result mysql_query($dbQuery) or die("Couldn't get file list");
    
if(
mysql_num_rows($result) == 1)
{
    
$fileType = @mysql_result($result0"blobType");
    
$fileContent = @mysql_result($result0"blobData");
}

if (
$fileType=="image/jpeg")

{
put something here that will redirect user to another page that
echos out first your desired HTML then the $filetype header
then
the $filedata blob
}
elseif (
$fileType=="image/gif")
{
put GIF handling code here as above for Jpegs
}
else
{
    echo 
"Record doesn't exist.";


Reply With Quote
  #26  
Old November 28th, 2002, 01:13 AM
patco patco is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 9 patco User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
New Page does not work

There is no problem redirecting to a new page. In fact that is what the script showfiles.php does. If what you suggested was tio work all I would have to do is wrap the download.php script in a html page with the necessary html outside the php code. This I tried but now you get the problem that the page itself has declared headers and now the php part is declaring headers with the result I get an error.

It beats me.

I have sent an email to the author asking that he might contribute to the discussion.

Last edited by patco : November 28th, 2002 at 01:16 AM.

Reply With Quote
  #27  
Old November 28th, 2002, 05:57 AM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Oh yeah, I get what you mean now. I'm at work at the mo, but I'll post a fuller response when I get home trying to solve the problem.

Reply With Quote
  #28  
Old November 28th, 2002, 01:52 PM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Right, yeah, got it now... you need to have the if/else loop on the showfiles page. So that if the mime type is X then the link is to downloadx.php and so on. Then shape each download page accordingly, taking out the snippets of code as and when you need to.

Reply With Quote
  #29  
Old November 28th, 2002, 01:58 PM
patco patco is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 9 patco User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks a million

I really appreciate your help and I am sure your suggestion will work however I am only learning PHP and wonder could you make the change to the showfiles page and download page for me so I can learn what to do in future.

Thanks

Pat

Reply With Quote
  #30  
Old November 28th, 2002, 02:58 PM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Sure, I'll be glad to help. Not entirely 100% sure myself, but I'll give it a shot tomorrow (it's 9pm here and I'm a tad busy) and let you know how I get on.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > BLOB Tutorial - PHP


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