如何在php中使用不同的表字段分别插入pdf和视频 [英] How to insert pdf and video separately with different table field in php

查看:79
本文介绍了如何在php中使用不同的表字段分别插入pdf和视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在单独的表格字段中插入pdf和视频,因为当前我同时使用这两种格式.这是我的插入代码

I have to insert pdf and video with separate table field because currently i am using one filed for both. Here my inserting code

<?php @session_start();
if(isset($_POST['send']))
{
include("db.php");
extract($_POST);
$detail=$_FILES['detail']['name'];
$detail=time()."-".$detail;
$path="upload/".$detail;
move_uploaded_file($_FILES['detail']['tmp_name'],$path);


$allowedExts = array("jpg", "jpeg", "gif", "png", "mp3", "mp4", "wma", "3gp");
$extension = pathinfo($_FILES['detail']['name'], PATHINFO_EXTENSION);

if ((($_FILES["detail"]["type"] == "video/mp4")
|| ($_FILES["detail"]["type"] == "audio/mp3")
|| ($_FILES["detail"]["type"] == "video/3gp")
|| ($_FILES["detail"]["type"] == "audio/wma")
|| ($_FILES["detail"]["type"] == "image/pjpeg")
|| ($_FILES["detail"]["type"] == "image/gif")
|| ($_FILES["detail"]["type"] == "image/jpeg"))

&& ($_FILES["detail"]["size"] < 20000)
&& in_array($extension, $allowedExts))

  {
  if ($_FILES["detail"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["detail"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["detail"]["name"] . "<br />";
    echo "Type: " . $_FILES["detail"]["type"] . "<br />";
    echo "Size: " . ($_FILES["detail"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["detail"]["tmp_name"] . "<br />";

   if (file_exists("upload/" . $_FILES["detail"]["name"]))
      {
      echo $_FILES["detail"]["name"] . " already exists. ";
      }
  else
      {
      move_uploaded_file($_FILES["detail"]["tmp_name"],
      "upload/" . $_FILES["detail"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["detail"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }

 
$query="insert into detail(detail_id,topic_id,detail) values('$detail_id','$topic_id','$detail')";

$q=mysql_query($query);
	if($q)
{
//echo "save successfully";
$_SESSION['msg']="Save Successfully.... Thank you";


}
else
{
//echo "try again..";
$_SESSION['msg']="Try again..";

}
}

?>

现在我必须为pdf和video使用两个不同的字段.当前要为pdf和video插入一个字段"detail".有人可以根据我的代码告诉我我该怎么做.

Now i have to use two different field for both pdf and video.Currently there is one field "detail" for both pdf and video to insert. will anyone please tell me according to my code that how can i do that.

推荐答案

您使用与上面相同的代码进行视频上传,并使用以下代码进行pdf上传:

You use same above code for Video upload and following code for pdf uploading :

    <?php
    if(isset($_POST['submit']))
    {
    $allowedExts = array("pdf");
    $temp = explode(".", $_FILES["file"]["name"]);
    $extension = end($temp);
    if ((($_FILES["file"]["type"] == "application/pdf")
    && ($_FILES["file"]["size"] < 20000)
    && in_array($extension, $allowedExts))
      {
      if ($_FILES["file"]["error"] > 0)
        {
        echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
        }
      else
        {
        echo "Upload: " . $_FILES["file"]["name"] . "<br>";
        echo "Type: " . $_FILES["file"]["type"] . "<br>";
        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
        echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
       if (file_exists("upload/" . $_FILES["file"]["name"]))
          {
          echo $_FILES["file"]["name"] . " already exists. ";
          }
        else
          {
          move_uploaded_file($_FILES["file"]["tmp_name"],
          "upload/" . $_FILES["file"]["name"]);
          echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
          }
        }
      }
    else
      {
      echo "Invalid file";
      }$query="insert into detail(detail_id,topic_id,detail) values('$detail_id','$topic_id','$detail')";

$q=mysql_query($query);
    if($q)
{
//echo "save successfully";
$_SESSION['msg']="Save Successfully.... Thank you";


}
else
{
//echo "try again..";
$_SESSION['msg']="Try again..";

}
}

?>

仅文件类型验证没有太多更改.

There is not much change only file type validation.

让我知道您是否还有其他问题.

Let me know if you face any other issue.

这篇关于如何在php中使用不同的表字段分别插入pdf和视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆