how to upload image???

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

Post Reply
fnleong
Forum Newbie
Posts: 18
Joined: Wed May 12, 2004 5:49 am

how to upload image???

Post by fnleong »

for upload image, i hav create a readdir.php for insert and encode the files into image table.

readdir.php

Code: Select all

<?php
<?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");

?>
?>
Last edited by fnleong on Thu May 13, 2004 3:45 am, edited 1 time in total.
fnleong
Forum Newbie
Posts: 18
Joined: Wed May 12, 2004 5:49 am

Post by fnleong »

and it can works i think. but the problem is images could'nt show .
fnleong
Forum Newbie
Posts: 18
Joined: Wed May 12, 2004 5:49 am

Post by fnleong »

and i use this list.php for list all my images from my table

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...Please search again!';
	exit();
	}
 
 
	printf("<TABLE BORDER WIDTH="100%%">\n");
	printf("<TR>
   
         <TD><B>id</B></TD>
         <TD><B>sixfourdata</B></TD>
	
	     
        </TR>\n");


	while (($row = mysql_fetch_object($result))){

	printf("<TR>
         <TD>%s</TD>
         <TD>%s</TD>
        
        </TR>\n",
	$row->imgid, base64_decode($row->sixfourdata));}
	printf("</TABLE>\n");
	mysql_free_result($result);



?>
?>
Last edited by fnleong on Thu May 13, 2004 3:45 am, edited 1 time in total.
fnleong
Forum Newbie
Posts: 18
Joined: Wed May 12, 2004 5:49 am

Post by fnleong »

and the problem is it can't list out the images, the images are list in code types
Post Reply