中转文件

 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
  include("./conn.php");
  include("./init.inc.php");
  include("./FCKeditor/fckeditor.php");
 
   
 
 
 
  session_start();
 //从PHP文件分配标量模板变量
  $page_title="新闻管理系统";
  $tpl->assign("page_title",$page_title);
 
  //从PHP文件分配数组到模板
  $sql="select * from news";
  $result = $mysqli->query($sql);
  $news=array();
  while($row = $result->fetch_assoc()){
     $news[]=$row;     
  }
  $tpl->assign("news",$news);  
 
  //来自配置文件的变量(作业)
 
  //局部缓存关闭
 //$tpl->register_block("nocache","fun1",false);
  // function fun1(){
  //   }
  //采取第二种办法
  //到plugins目录下新建文件
 
  //$tpl->assign("username",$_SESSION['username']);
 
 
 //fckeditor的使用
 function editor($name,$value){
    global $tpl;
    $editor = new FCKeditor($name);
 //指定在线编辑器的路径
 $editor->BasePath="./FCKeditor/" ;
 $editor->Toolbarset="Default";
 $editor->Height=500;
 $editor->Width="100%";
 $editor->Value=$value;
 $editor->Confit['AutoDetectLanguage']=true;
 $editor->Confit['DefalutLanguage']='en';
 $fck = $editor->CreateHtml();
 $tpl->assign("editor",$fck);
 }
 
 
 //根据地址栏的参数判断使用的模板
  $action=$_REQUEST['action'];//分配的变量是一样的
  $id=$_REQUEST['id'];
  switch($action){
     case   "addnewsview":
         
          $tpl->assign("page_title","添加新闻"); 
    $tpl->assign("actionvalue","addnews");  
    $tpl->assign("content_title","添加新闻管理");
    editor("content","");
       $tpl->display("addnews.html");
    break;
  case   "addnews":
          $title = $_REQUEST['title'];
    $content = $_REQUEST['content'];
    //$db=new mysql();
          $button=$_REQUEST['Submit'];
    if(empty($title) || empty($content)){
              echo "请填写完成!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1;                   URL=./index.php?action=addnewsview\">";
          }else{
           $sql="insert into news                       values(id,'admin','$title','$content',NOW())";
               $db->query_exec($sql);
                  echo "操作成功!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1;                     URL=./index.php\">";
         }
            break;
   
   
   
   
   
   
   
   
   
   
   
   case  "delnews":
           $result = $mysqli->query("select * from news where                                           id={$_REQUEST['id']}");
     //$row = $result->num_rows();
       for($i=0;$i<=count($result);$i++){
          $sql = "delete from news where id={$_REQUEST['id']}";
   
   }
   
   
   
   
   
   
   
       
          break;
          //分配模板变量
    //指定模板文件
   default:
             $tpl->assign("page_title","新闻管理");
    $tpl->assign("cotent_title","新闻管理");
    $tpl->assign("actionvalue","delnews");
    $mysqli->query($sql);
    $sql1="select * from news";
    $result=$mysqli->query($sql1);
    while($row = $result->fetch_assoc()){
        $news[]=$row;
    }
      $tpl->assign("news",$news);
         $tpl->display("index.html");
 
  }
 
 
 
 
 
 
  
 
 
?>
以下是一个使用SpringBoot编写的中转文件接口的示例代码,包括注释以解释每个部分的作用。 ```java @RestController public class FileTransferController { @Autowired private ResourceLoader resourceLoader; @PostMapping("/transfer") public ResponseEntity<Resource> transferFile(@RequestParam("file") MultipartFile file, @RequestParam(value = "type", required = false) String fileType) { // 获取文件名和类型 String fileName = file.getOriginalFilename(); String contentType = file.getContentType(); // 如果没有传递文件类型,则使用文件的实际类型 if (fileType == null) { fileType = contentType; } // 将文件保存到服务器的临时目录中 try { File tempFile = File.createTempFile("temp", null); file.transferTo(tempFile); // 将文件返回给客户端 Resource resource = resourceLoader.getResource("file:" + tempFile.getAbsolutePath()); return ResponseEntity.ok() .contentType(MediaType.parseMediaType(fileType)) .contentLength(resource.contentLength()) .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"") .body(resource); } catch (IOException e) { e.printStackTrace(); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); } } } ``` 这个控制器类有一个`transferFile`方法,这个方法接收一个`MultipartFile`类型的文件和一个可选的`type`参数。如果提供了`type`参数,则将其用作文件的MIME类型,否则使用文件的实际MIME类型。 然后,该方法将文件保存到服务器的临时目录中,并使用Spring的`ResourceLoader`来获取文件的资源对象。最后,该方法将资源对象包装在一个`ResponseEntity`中,并将其返回给客户端。客户端可以使用此响应打开或下载文件。 此示例中的中转文件接口可以通过POST方法调用,如下所示: ``` POST /transfer HTTP/1.1 Host: example.com Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="file"; filename="example.pdf" Content-Type: application/pdf <@INCLUDE *path-to-file*/example.pdf> ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="type" application/pdf ------WebKitFormBoundary7MA4YWxkTrZu0gW-- ``` 在这个示例中,我们使用了一个名为`file`的表单字段来上传文件,并在另一个名为`type`的字段中提供了可选的文件类型。此请求将上传一个名为`example.pdf`的PDF文件,并将其保存在服务器上的临时目录中。服务器将返回一个包含`example.pdf`的PDF文件的`ResponseEntity`。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值