Rumah > pembangunan bahagian belakang > tutorial php > 图片存储与浏览一例(Linux+Apache+PHP+MySQL)_PHP教程

图片存储与浏览一例(Linux+Apache+PHP+MySQL)_PHP教程

WBOY
Lepaskan: 2016-07-21 16:01:12
asal
923 orang telah melayarinya

注意本程序使用的表结构为:
    use test;
    create table image(
                       id int unsigned auto_increment primary key,
                       description text,
                       filename varchar(50),
                       filesize int,
                       filetype varchar(50),
                       filedata longblob
                      );
*/

//?cmd={read|list|form|store}

//检查cmd参数的合法性
switch($cmd){
   case 'read':
      break;
   case 'list':
      break;
   case 'form':
      break;
   Case 'store':
      break;
   default:
      $cmd = 'list';
      break;
}

switch($cmd){
   case 'read':
      //?cmd=read&id={}
      //读一个图片
      $server = mysql_connect("localhost","test","") or die("无法连接数据库服务器");
      mysql_select_db("test",$server) or die("无法连接数据库");
      $sql = "select filetype,filedata from image where id='$id'";
      $rst = mysql_query($sql,$server) or die("$sql查询出错");
      if($row=mysql_fetch_row($rst)){
         header("Content-Type:" . $row[0]);
         echo $row[1];
      }
      else{
         echo "没有找到该记录";
      }
      mysql_free_result($rst);
      mysql_close($server) or die("无法与数据库服务器断开连接");
      break;
   case 'list':
      //?cmd=list
      //显示所有图片
      echo '';
      echo '

图片存储与浏览一例';
      echo '';
      echo '显示所有图片';
      echo "    ";
      echo '上传图片';
      $server = mysql_connect("localhost","test","") or die("无法连接数据库服务器");
      mysql_select_db("test",$server) or die("无法连接数据库");
      $sql = "select id,description,filename,filetype,filesize from image";
      $rst = mysql_query($sql,$server) or die("$sql查询出错");
      while($row=mysql_fetch_row($rst)){
         echo "
";
         echo "描述:" . $row[1] . "
";
         echo "文件名:" . $row[2] . "
";
         echo "类型:" . $row[3] . "
";
         echo "大小:" . $row[4] . "
";
         echo '图片存储与浏览一例(Linux+Apache+PHP+MySQL)_PHP教程';
      }
      mysql_free_result($rst);
      mysql_close($server) or die("无法与数据库服务器断开连接");
      echo '';
      echo '';
      break;
   case 'form':
?>


图片存储与浏览一例



描述:



文件:







      break;
   case 'store':
      //?cmd=store&description={}&file={}&file_size={}&file_type={}&file_name={}
      //存储图片
      echo '';
      echo '图片存储与浏览一例';
      echo '';
      echo '显示所有图片';
      echo "    ";
      echo '上传图片';
      $server = mysql_connect("localhost","test","") or die("无法连接数据库服务器");
      mysql_select_db("test",$server) or die("无法连接数据库");
      $data = addslashes(fread(fopen($file,"r"),filesize($file)));
      $sql = "insert into image(description,filename,filetype,filesize,filedata)
              values('$description','" . basename($file_name) . "','$file_type',$file_size,'$data')";
      mysql_query($sql,$server) or die("$sql执行出错");
      $id = mysql_insert_id();
      echo "
你上传的图片效果:
";
      echo '图片存储与浏览一例(Linux+Apache+PHP+MySQL)_PHP教程';
      mysql_close($server) or die("无法与数据库服务器断开连接");
      echo '';
      echo '';
      break;
}
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/316853.htmlTechArticle注意本程序使用的表结构为: use test; create table image( id int unsigned auto_increment primary key, description text, filename varchar(50), filesize int, filetype varcha...
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan