PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
fnleong
Forum Newbie
Posts: 18 Joined: Wed May 12, 2004 5:49 am
Post
by fnleong » Wed May 12, 2004 5:49 am
Code: Select all
<?php
<php?
@ $db = mysql_pconnect('localhost','root');
if (!$db)
{
echo 'Error: no record to database. Please try again later.';
exit;
}
mysql_select_db('mobile');
$query = "SELECT * FROM images";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
if(!$num_results)
{
echo 'No pics can be found!';
exit();
}
printf("<TABLE BORDER WIDTH="100%%">\n");
printf("<TR>
<TD><B>User Name</B></TD>
<TD><B>Password</B></TD>
</TR>\n");
while (($row = mysql_fetch_array($result)))
{
$imgid = $row["imgid"];
$encodeddata = $row["sixfourdata"];
printf("<TR>
<TD>%s</TD>
<TD>%s</TD>
</TR>\n",
$row->imgid, $row->$encodeddata);}
printf("</TABLE>\n");
mysql_free_result($result);
}
echo 'base64_decode($encodeddata)';
?>
?>
Last edited by
fnleong on Thu May 13, 2004 3:47 am, edited 1 time in total.
fnleong
Forum Newbie
Posts: 18 Joined: Wed May 12, 2004 5:49 am
Post
by fnleong » Wed May 12, 2004 5:51 am
<?php
$dbcnx = @mysql_connect("localhost", "root", "");
if (!$dbcnx)
{
echo( "connection to database server failed!" );
exit();
}
if (! @mysql_select_db("mobile") )
{
echo( "Image Database Not Available!" );
exit();
}
$path = "./";
$dir_handle = @opendir($path) or die("Unable to open directory $path");
while ($file = readdir($dir_handle))
{
$filetyp = substr($file, -3);
if ($filetyp == 'gif' OR $filetyp == 'jpg')
{
$handle = fopen($file,'r');
$file_content = fread($handle,filesize($file));
fclose($handle);
$encoded = chunk_split(base64_encode($file_content));
$sql = "INSERT INTO images SET sixfourdata='$encoded'";
@mysql_query($sql);
}
}
closedir($dir_handle);
echo("complete");
patrikG
DevNet Master
Posts: 4235 Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK
Post
by patrikG » Wed May 12, 2004 6:30 am
click the first link below - and don't double-post again.
Bill H
DevNet Resident
Posts: 1136 Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:
Post
by Bill H » Wed May 12, 2004 8:22 am
And, given that you made even one post, why?
To show us that you can write code?
So can we. Big deal.
launchcode
Forum Contributor
Posts: 401 Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:
Post
by launchcode » Wed May 12, 2004 8:29 am
I think he's asking for help - the subject of his messages seems to imply that anyway. Trying to chunk encode an image into a SQL table for some reason.