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:
  #31  
Old November 30th, 2002, 08:24 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
Here's a small snippet from the showfiles.php page, you can see where I have made changes, and how you will need to make up your own new pages for images etc...


PHP Code:
<?
$dbQuery 
"SELECT blobId, blobTitle, blobType, downloads, description FROM downloads ORDER BY downloads DESC";

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

?> 

<table border="1" cellpadding="0" cellspacing="0" bordercolor="#111111" width="99%"> 

<tr> 

<td bgcolor="#000000" height="21"> 
<p style="margin-left: 10" class=tabletext>DESCRIPTION</p>
</td> 

<td bgcolor="#000000" height="21"> 
<p style="margin-left: 10" class=tabletext>TYPE</p>
</td>

<td bgcolor="#000000" height="21"> 
<p style="margin-left: 10" class=tabletext>DOWNLOADS</p>
</td>

<td bgcolor="#000000" height="21"> 
<p style="margin-left: 10" class=tabletext>FILE</p>
</td>
</tr> 

<?php 
while($row mysql_fetch_array($result)) 

?> 

<tr> 
<td bgcolor="#000000" height="21"> 
<p style="margin-left: 10; margin-right: 10"> 
<font face=Verdana size=1 color=FFFFFF>
<?php echo strtoupper($row["blobTitle"]); ?><br>
<?php echo ($row["description"]); ?>
</font>
</td> 

<td bgcolor="#000000" height="21"> 
<p style="margin-left: 10"> 
<font face=Verdana size=1 color=FFFFFF>
<?php echo $row["blobType"]; ?> 
</font>
</td>

<td bgcolor="#000000" height="21"> 
<p style="margin-left: 10"> 
<font face=Verdana size=1 color=FFFFFF>
<?php echo $row["downloads"]; ?> 
</font>
</td>
<!-- check to see what type of file we're to download -->
<? if ($row["blobType"]=="image/jpeg")

?>
<td bgcolor="#000000" height="21"> 
<p style="margin-left: 10">
<font face=Verdana size=1 color=FFFFFF>
<a href="downloadimage.php?fileId=<?php echo $row["blobId"]; ?>">
<?
}
else
{
<
td bgcolor="#000000" height="21"
<
p style="margin-left: 10">
<
font face=Verdana size=1 color=FFFFFF>
<
a href="downloadnormalfile.php?fileId=<?php echo $row["blobId"]; ?>">
}
?>
DOWNLOAD NOW 
</a>
</font>
</td> 
</tr>

Last edited by Kanu : November 30th, 2002 at 08:28 AM.

Reply With Quote
  #32  
Old January 27th, 2003, 02:54 AM
markrenn markrenn is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 23 markrenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
register globals off

Is there a way i can run this with "register globals" set to off.

I got it all working with the globals turned on... the problem is that our sysad wants me to optimize the script so he could turn off the globals

HELLLLPPP pls. thanks!

Reply With Quote
  #33  
Old January 27th, 2003, 03:13 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
Re: register globals off

Quote:
Originally posted by markrenn
Is there a way i can run this with "register globals" set to off.

I got it all working with the globals turned on... the problem is that our sysad wants me to optimize the script so he could turn off the globals

HELLLLPPP pls. thanks!


Yes there is, I will look into it when I get home. (about 9 hours time from this post)

Reply With Quote
  #34  
Old January 27th, 2003, 10:02 PM
markrenn markrenn is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 23 markrenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
looking 4ward

thanks kanu, im looking forward to whatever help you could provide

Reply With Quote
  #35  
Old January 28th, 2003, 12:03 AM
ramz ramz is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Juiz de Fora - MG- Brazil
Posts: 93 ramz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Send a message via ICQ to ramz Send a message via MSN to ramz
Yes... sure

To manipulate uploaded files with globals off, use this:

GLOBALS ON GLOBALS OFF
---------------------------------------------------------------------
$myfile $_FILES["myfile"]["tmp_name"]
$myfile_name $_FILES["myfile"]["name"]
$myfile_size $_FILES["myfile"]["size"]
$myfile_type $_FILES["myfile"]["type"]

To handle multipe files uploaded, use like this:

$_FILES["myfile"]["tmp_name"][0] // The 1st uploaded file
$_FILES["myfile"]["tmp_name"][1] // The 2nd uploaded file
$_FILES["myfile"]["tmp_name"][2] // The 3rd uploaded file

$_FILES["myfile"]["name"][0] // The 1st uploaded file
$_FILES["myfile"]["name"][1] // The 2nd uploaded file
$_FILES["myfile"]["name"][2] // The 3rd uploaded file

$_FILES["myfile"]["size"][0] // The 1st uploaded file
$_FILES["myfile"]["size"][1] // The 2nd uploaded file
$_FILES["myfile"]["size"][2] // The 3rd uploaded file

Hope that this helps...
__________________
Regards,
Ramiro Varandas Jr.

Reply With Quote
  #36  
Old January 28th, 2003, 09:14 AM
baines baines is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 33 baines User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 51 sec
Reputation Power: 16
Question File Size?

Hi Guys

I didn’t have too many problems getting this to work once I’d sorted out the global variables.
I basically use these things to teach myself something new and then go away and rewrite them completely just to reinforce the concepts……

However, I do have one problem still.

It works great for some files but not on others. It seems to relate to file size. While I have no problems uploading 4 or 5 hundred Kb, anything over 1Mb stops at mysql_query($dbQuery) or die("Couldn't add file to database"); giving the error.

I’ve checked the obvious and in PHP.INI, upload_max_filesize is 4Mb, way bigger than the files I’m testing with.

Anyone else had this issue?

PHP4.3.0
MySQL 3.23.52-nt
Windows 2000 and IIS

Reply With Quote
  #37  
Old January 28th, 2003, 02:34 PM
ramz ramz is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Juiz de Fora - MG- Brazil
Posts: 93 ramz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Send a message via ICQ to ramz Send a message via MSN to ramz
Hi.
You could try using the function is_uploaded_file($var_filename) to check if the file has been fully uploaded. If yes, then you can try inserting it on the database. And, are you using addslashes()?

Reply With Quote
  #38  
Old January 28th, 2003, 02:36 PM
ramz ramz is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Juiz de Fora - MG- Brazil
Posts: 93 ramz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Send a message via ICQ to ramz Send a message via MSN to ramz
Check this too


Reply With Quote
  #39  
Old January 28th, 2003, 04:30 PM
baines baines is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 33 baines User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 51 sec
Reputation Power: 16
Thanks for this Ramz

post_max_size is set to 8Mb and yes, I am using addslashes()
In fact, with the exception of using $_FILES to recover the variable, the script is as it appears on the tutorial.

As for is_uploaded_file($var_filename). Good point.
Unfortunately I won't be able to test this for a couple of days as I'm working away from the office.

Interestingly enough, the file size is reported correctly when I echo all the variables. I am guessing that this information is sent along with the file data, rather than being calculated by the server once the upload is complete. Is this right?

The only other modifcation I've made is to use "rb" instead of just "r" in the line $fileHandle = fopen($fileUpload, "r");
I read that this is necessary for Windows based systems but it didn't make much difference either way.

I'll let you know how it turns out.

Cheers

Baines

Reply With Quote
  #40  
Old January 29th, 2003, 08:07 PM
markrenn markrenn is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 23 markrenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Re: Yes... sure

Quote:
Originally posted by ramz
To manipulate uploaded files with globals off, use this:

GLOBALS ON GLOBALS OFF
---------------------------------------------------------------------
$myfile $_FILES["myfile"]["tmp_name"]
$myfile_name $_FILES["myfile"]["name"]
$myfile_size $_FILES["myfile"]["size"]
$myfile_type $_FILES["myfile"]["type"]


Hope that this helps...


thanks for the post ramz!... it's just that i didnt exactly get what you mean... using this given variables from the original codes?
global $strDesc;
global $fileUpload;
global $fileUpload_name;
global $fileUpload_size;
global $fileUpload_type;


Kanu> is this the same solution you got?

Reply With Quote
  #41  
Old January 29th, 2003, 10:04 PM
ramz ramz is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Juiz de Fora - MG- Brazil
Posts: 93 ramz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Send a message via ICQ to ramz Send a message via MSN to ramz
Hi markrenn!
To use those variables as globals in your code, just do this:

$_POST["strDesc"];
$_FILES["fileUpload"]["tmp_name"];
$_FILES["fileUpload"]["name"];
$_FILES["fileUpload"]["size"];
$_FILES["fileUpload"]["type"];

This is already global... so you don't need to put the word: global in the front of it.
Using like this is global in your entire code... even inside functions and classes.

Reply With Quote
  #42  
Old January 29th, 2003, 11:04 PM
markrenn markrenn is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 23 markrenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
got an error on that

here's the code i used,
PHP Code:
<?php
    
global $strDesc;
global 
$fileUpload;
global 
$fileUpload_name;
global 
$fileUpload_size;
global 
$fileUpload_type;

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

// Database connection variables
    
$dbServer 'localhost';
    
$dbUser 'iamtheuser';
    
$dbPass 'password';
    
$dbDatabase 'dbdbdbdb';

$fileHandle fopen($fileUpload"r");
$fileContent fread($fileHandle$fileUpload_size);
$fileContent addslashes($fileContent);
$image getimagesize($fileUpload);
$width $image[0];
$height =$image[1];
$widthLonger 0;
if(
$width $height)
$widthLonger 1;}
if (
$width 200 || $height 150)
{
header("Location: uploadfail.php");}
else {
$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");
if(
$fileUpload_size >= 15000)
{
header("Location: uploadfail.php");}
elseif(
$fileUpload_type == "image/gif" )
{
$dbQuery  "INSERT INTO userLogos VALUES ";
$dbQuery .= "(0, '$userId', '$strDesc', '$fileContent', '$fileUpload_type', '$widthLonger')";
mysql_query($dbQuery) or die("Couldn't add file to database");
header("Location: showuserimage.php");
}else { 
header("Location: uploadfail.php");}}
?>


but when i replaced the variables, i got this instead
Parse error: parse error, unexpected T_CHARACTER, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\public_html\get\grabimage.php on line 51

is there something i missed?

Last edited by markrenn : January 29th, 2003 at 11:11 PM.

Reply With Quote
  #43  
Old January 29th, 2003, 11:25 PM
ramz ramz is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Juiz de Fora - MG- Brazil
Posts: 93 ramz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Send a message via ICQ to ramz Send a message via MSN to ramz
Try this

<?php

// Make sure both a description and
// file have been entered
if(empty($_POST["strDesc"]) || $_FILES["fileUpload"]["name"] == "") {
die("You must enter both a name and file");
}

// Database connection variables
$dbServer = 'localhost';
$dbUser = 'iamtheuser';
$dbPass = 'password';
$dbDatabase = 'dbdbdbdb';

$fileHandle = fopen($_FILES["fileUpload"]["tmp_name"], "rb");
$fileContent = fread($fileHandle, $_FILES["fileUpload"]["size"]);
$fileContent = addslashes($fileContent);
$image = getimagesize($_FILES["fileUpload"]["tmp_name"]);
$width = $image[0];
$height =$image[1];
$widthLonger = 0;
if($width > $height)
{ $widthLonger = 1;}
if ($width > 200 || $height > 150){
header("Location: uploadfail.php");
} else {
$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");
if($_FILES["fileUpload"]["size"] >= 15000) {
header("Location: uploadfail.php");
} elseif($_FILES["fileUpload"]["type"] == "image/gif" ) {
$dbQuery = "INSERT INTO userLogos VALUES ";
$dbQuery .= "(0, '$userId', '$strDesc', '$fileContent', '". $_FILES["fileUpload"]["type"] . "', '$widthLonger')";
mysql_query($dbQuery) or die("Couldn't add file to database");
header("Location: showuserimage.php");
} else {
header("Location: uploadfail.php");
}
}
?>

Reply With Quote
  #44  
Old January 30th, 2003, 01:36 AM
markrenn markrenn is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 23 markrenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up thanks ramz!

i must say, thanks a lot ramz!!!!

Reply With Quote
  #45  
Old January 30th, 2003, 06:42 AM
baines baines is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 33 baines User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 51 sec
Reputation Power: 16
Angry File Size still a problem

The PHP manual states that post_max_size should be larger than upload_max_size and memory_limit should be larger than post_max_size

My PHP.INI file now contains the following lines;

memory_limit=8M
post_max_size=7M
upload_max_filesize=5M


These setting should be able to handle the 1.5 – 2Mb files that I need to be able to store, most of which are PDF’s of user manuals and product reviews.

Currently, if I get even close to 1Mb, the script fails at the point of adding the data in to the database (Couldn’t add file to database)

Echoing the important variables shows that $fileUpload_size is correct and testing with

if (is_uploaded_file($fileUpload)) echo("Fully Uploaded");

as Ramz suggested, seems to show that the file is indeed making it up to the server intact and complete.

I’m now completely stumped.

Any suggestions are very welcome.

Reply With Quote
  #46  
Old January 31st, 2003, 07:22 AM
baines baines is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 33 baines User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 51 sec
Reputation Power: 16
Lightbulb Filse Size Problem Resolved

Well Guys..... I've solved the file size problem...

It turns out that MySQL has a max_allowed_packet directive and mine was set to 1Mb. ( this seems to be a default setting)

It's taken several hours to get through all the technical stuff (servers and services are not my strong point!) but here is the solution for anyone else who comes across the problem.

mysqld --set-variable=max_allowed_packet=xM where 'x' is the number of Mb.

I've set mine to 8Mb and I'm now happily blobbing along with the rest of you.

I expect this is a temporary solution and probably won’t survive a restart but I’ll cross the bridge when I come to it. If anyone knows how I can set this up to be automatic, it would be a great help, I find the MySQL manual a bit too advanced in some areas.

Thanks for all the help along the way.

Reply With Quote
  #47  
Old May 5th, 2003, 01:38 AM
markrenn markrenn is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 23 markrenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Re: Filse Size Problem Resolved

Quote:
Originally posted by baines
Well Guys..... I've solved the file size problem...

It turns out that MySQL has a max_allowed_packet directive and mine was set to 1Mb. ( this seems to be a default setting)

It's taken several hours to get through all the technical stuff (servers and services are not my strong point!) but here is the solution for anyone else who comes across the problem.

mysqld --set-variable=max_allowed_packet=xM where 'x' is the number of Mb.

I've set mine to 8Mb and I'm now happily blobbing along with the rest of you.

I expect this is a temporary solution and probably won’t survive a restart but I’ll cross the bridge when I come to it. If anyone knows how I can set this up to be automatic, it would be a great help, I find the MySQL manual a bit too advanced in some areas.

Thanks for all the help along the way.


how do i edit this variables? i checked with my winmysqladmin and the max_allowed_packet value is 1048576

please help

Reply With Quote
  #48  
Old May 6th, 2003, 09:33 PM
infamous-online infamous-online is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Posts: 403 infamous-online User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 27 m 25 sec
Reputation Power: 17
anybody using a windows machine cause i am using win2k and i can't get this script to work
__________________
Apache Expert

Reply With Quote
  #49  
Old May 6th, 2003, 10:13 PM
markrenn markrenn is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 23 markrenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
seems we have the same problem asp_man

Reply With Quote
  #50  
Old May 11th, 2003, 09:07 PM
andr3s andr3s is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 3 andr3s User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
HELP!!, the following code does not work, Could you guys hlp me please?

<?php
if(!$_GET["x"]) {
echo("<form method=post action=index.php?x=1 enctype=\"multipart/form-data\"><input type=file name=archivo><input type=submit></form>");
} else {
$a = fopen($_FILES["archivo"]["tmp_name"], "rb");
$leer = fread($a , $_FILES["archivo"]["size"]);
$leer = addslashes($leer);
header("Content-Type: $_FILES[archivo][type]");
echo($leer);
}
?>

Reply With Quote
  #51  
Old May 16th, 2003, 06:01 PM
baines baines is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 33 baines User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 51 sec
Reputation Power: 16
Hi Guys

I thought this thread had died long ago

Anyhow, I'm using win2K and I did eventually work out all the problems.

Sorry for the delay but I've just arrived back from two weeks in the South of France (How lucky am I?)

I'll post my working scripts and try and figure out the the max packet size thing once I'm back in the office on Monday morning.

Baines

Reply With Quote
  #52  
Old May 16th, 2003, 08:48 PM
infamous-online infamous-online is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Posts: 403 infamous-online User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 27 m 25 sec
Reputation Power: 17
Thumbs up

Quote:
Originally posted by baines
Hi Guys

I thought this thread had died long ago

Anyhow, I'm using win2K and I did eventually work out all the problems.

Sorry for the delay but I've just arrived back from two weeks in the South of France (How lucky am I?)

I'll post my working scripts and try and figure out the the max packet size thing once I'm back in the office on Monday morning.

Baines


good cause i would love to use this to make my site more dynamic

Reply With Quote
  #53  
Old May 17th, 2003, 04:00 AM
baines baines is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 33 baines User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 51 sec
Reputation Power: 16
Quote:
Originally posted by andr3s
HELP!!, the following code does not work, Could you guys hlp me please?

<?php
if(!$_GET["x"]) {
echo("<form method=post action=index.php?x=1 enctype=\"multipart/form-data\"><input type=file name=archivo><input type=submit></form>");
} else {
$a = fopen($_FILES["archivo"]["tmp_name"], "rb");
$leer = fread($a , $_FILES["archivo"]["size"]);
$leer = addslashes($leer);
header("Content-Type: $_FILES[archivo][type]");
echo($leer);
}
?>


Is this just that you are checking for GET data in your IF condition but using POST data in the form?

Reply With Quote
  #54  
Old May 19th, 2003, 05:48 AM
baines baines is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 33 baines User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 51 sec
Reputation Power: 16
Post Configure MAX_ALLOWED_PACKET

To configure MySQL to allow uploading of files bigger than 1Mb you need to configure MySQL’s MAX_ALLOWED_PACKET variable.

This can be set in the “my.ini” or “my.cnf” file. Search your system for one of these files and add the line

set-variable=max_allowed_packet=xM

where x is the size you require in Mb.

Save your changes and reboot the system.

For more information refer to the manual supplied. You can normally find this at mysql\docs\manual.html or on line at http://www.mysql.com/doc/en/Option_files.html

Hope this helps

Baines

Reply With Quote
  #55  
Old May 19th, 2003, 05:56 AM
baines baines is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 33 baines User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 51 sec
Reputation Power: 16
Download Script

Here is the script that fetches the blobs from the database. As far as I can remember, the only thing I changes was the $_GET['fileId'] to make it work with register globals off.


downloadfile.php
Don't forget to change your username, password and host details!

PHP Code:
<?php 

$blobId
=$_GET['fileId'];

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

// Database connection variables 
$dbServer "localhost"
$dbDatabase "myFiles"
$dbUser "YourUsername";
$dbPass "YourPassword";

$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

else 

echo 
"Record doesn't exist."


?>

Last edited by baines : May 19th, 2003 at 06:02 AM.

Reply With Quote
  #56  
Old May 19th, 2003, 05:59 AM
baines baines is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 33 baines User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 51 sec
Reputation Power: 16
Grab Files Script

Again, the only changes have been to the variables for use under the new global variables off rule.

Again, remeber to change your connection details.

PHP Code:
<?php 

// 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. 

$strDesc=$_POST['strDesc']; 
$fileUpload=$_FILES['fileUpload']['tmp_name']; 
$fileUpload_name=$_FILES['fileUpload'] ['name']; 
$fileUpload_size=$_FILES['fileUpload'] ['size']; 
$fileUpload_type=$_FILES['fileUpload'] ['type']; 

echo(
"<br><br><br>fileupload=".$fileUpload);
echo(
"<br>name=".$fileUpload_name);
echo(
"<br><br><br>size=".$fileUpload_size);

if (
is_uploaded_file($fileUpload)) echo("Fully Uploaded");

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


// Database connection variables 
$dbServer "localhost"
$dbDatabase "myFiles"
$dbUser "YourUsername"
$dbPass "YouePassword"


$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>"

?>

Reply With Quote
  #57  
Old June 18th, 2003, 01:11 PM
agontijo agontijo is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: BH - Brazil
Posts: 1 agontijo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi guys,

I'm a newbie in the PHP/MySQL field and I have a problem that is very similar to this discussion.

I got the image uploaded to the database correctly, with the following code:

============================\\\\\
<?
$caminho = "d:/inetpub/wwwroot/alex/img/"; // the path of the images
if(empty($file)) {
?>
<title>Upload Image</title>
<form method="POST">
Imagem: <input type="file" name="file"><br>
Formato: <select name="formato">
<option value="gif">Gif</option>
<option value="jpeg">Jpg</option>
</select><br>
<input type="submit" value="Enviar">
</form>
<?

$db = mysql_connect("localhost", "root", "");
mysql_select_db("site",$db);

} elseif(!empty($file)) {
$arq = $file;
if(move_uploaded_file($file."/".$arq, $caminho."/".$arq)) {
$abre = fopen($caminho."/".$arq, "r");
$le = fread($abre, filesize($caminho."/".$arq));
fclose($abre);
$qr = "INSERT INTO imagens (formato,imagem) VALUES('".$formato."','".addslashes($le)."')";
mysql_query($qr) or die(mysql_error());
} else {
echo "Nao foi possivel enviar a imagem!";
}
}
?>

============================////

This is working very good. I can upload the image and my database shows it right away.

But I got stucked in viewing the f*** image! I need to see the image together with .html codes. But I can't do that with the following code. This code works, but just alone. See:

============================\\\\
<?php
$db = mysql_connect("localhost", "root", "");
mysql_select_db("site",$db);

$qr = "SELECT * FROM imagens ORDER BY id_img DESC";
$sql = mysql_query($qr);
$l = mysql_fetch_array($sql);
header("Content-type: image/".$l[tipo]);
echo stripslashes($l["dados"]);
?>
============================////

One guy told me that this code can only works in this way, pure php, but I need to mix it with .html, because I need to show the image along the description.

Does anyone knows some code that I can use to show the image into mixed php with html?

If anyone can help..., thanks a lot!!!

Regards,

Alex

Reply With Quote
  #58  
Old June 18th, 2003, 08:48 PM
markrenn markrenn is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 23 markrenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
try using this for the image source

<img src='downloadfile.php?Id=<?php echo $row["BlobId"]; ?>'>

good luck
marky

Reply With Quote
  #59  
Old June 20th, 2003, 09:16 AM
alisafwan alisafwan is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: pakistan
Posts: 18 alisafwan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 sec
Reputation Power: 0
Hi Kanu

hello sir

i am ali from pakistan
i tried to use the code u posted in the form of attachment of blobing data in mysql
but its not working on my pc

upload_tmp_dir and
upload_max_filesize

are set
but still its not working for any kind of file can u help me


ali safwan

Reply With Quote
  #60  
Old July 3rd, 2003, 05:59 PM
YettiDesign YettiDesign is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Brisbane, Australia
Posts: 5 YettiDesign User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Ive had a few problems with this tutorial also.

my problem now is that i have cut and chopped it etc etc...
and when i click to save a file, it says to save it as: test_fil_create.php

not the original file name!!

code is : (temp.php)

<?php
$do = $HTTP_GET_VARS["do"];
if ($do == "") {
if (!isset($_REQUEST["cmdSubmit"])) {
printf("<FORM NAME=\"frmUploadFile\" METHOD=POST ACTION=\"$PHP_SELF\" enctype=\"multipart/form-data\">");
printf("<INPUT TYPE=\"File\" NAME=\"fileUpload\">");
printf("<INPUT TYPE=\"Submit\" NAME=\"cmdSubmit\" VALUE=\"Load File\">");
printf("</FORM>");
}
else {
$fileUpload = $_FILES['fileUpload'];
$fileUpload_name = $_FILES['fileUpload']['name'];
$fileUpload_size = $_FILES['fileUpload']['size'];
$fileUpload_type = $_FILES['fileUpload']['type'];
$fileHandle = fopen($_FILES['fileUpload']['tmp_name'], "rb");
$fileContent = fread($fileHandle, $fileUpload_size);
$fileContent = addslashes($fileContent);
$db = @mysql_connect("localhost") or exit("SERVER unavailable");
@mysql_select_db("temp", $db) or exit("DB unavailable");
$sql = "INSERT INTO tmpfile VALUES('','". $fileUpload_name ."','". $fileUpload_type ."','". $fileContent ."','')";
@mysql_query($sql,$db) or exit("QUERY failed");
mysql_close($db);
echo "<h1> File Uploaded </h1>";
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>";
echo "<A HREF=\"$PHP_SELF?do=view\"> View File </A>";
}
}
else {
if ($do == "view") {
$db = @mysql_connect("localhost") or exit("SERVER unavailable");
@mysql_select_db("temp", $db) or exit("DB unavailable");
$sql = "SELECT filid,filname from tmpfile order by filid";
$result = @mysql_query($sql,$db) or exit("QUERY failed");
echo "<TABLE BORDER=1>\n";
echo "<TR><TH>filid</TH><TH>filtype</TH><TH>imgdata</TH></TR>\n";
while ($rs=mysql_fetch_array($result)) {
echo "<TD>" .$rs[0]."</TD>";
echo "<TD>" .$rs[1]."</TD>";
echo "<TD><A HREF=\"test_fil_create.php?filid=".$rs[0]."\">download now </
A></TD></TR>";
}
echo "</TABLE>";
mysql_close($db);
}
}
?>


(test_fil_create.php)
<?php
$db = @mysql_connect("localhost") or exit("SERVER unavailable");
@mysql_select_db("temp",$db) or exit("DB unavailable");
$sql = "SELECT filtype,fildata from tmpfile where filid=". $HTTP_GET_VARS["filid"];
$result = @mysql_query($sql,$db) or exit("QUERY failed");
$contenttype = @mysql_result($result,0,"filtype");
$image = @mysql_result($result,0,"fildata");
header("Content-type: $contenttype");
echo $image;
mysql_close($db);
?>




its kinda frustrating.. :S
if i type in the original name, it saves and works fine... so i just want the "save box" to display the files original name!
any suggestions? or something i missed.

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