dtcn30461 2015-07-21 22:49
浏览 87

是否可以将这些文件上传到MySQL数据库?

In my file upload script, I currently have all the files going to an /upload directory. Is it possible for me to upload it to a database as well as the upload directory so it is easier for me to manage?

<?php

require 'header.php';

?>

<center>
<?php

$uniqueid = uniqid();
$file = $uniqueid. basename( $_FILES["fileToUpload"]["name"]);
$target_dir = "uploads/$uniqueid";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
    $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
    if($check !== false) {
        //echo "File is not an image.";
      //  $uploadOk = 1;
    }
}
?>
<br>
<?php
// Check if file already exists
if (file_exists($target_file)) {
    echo " Sorry, the file already exists or";
    $uploadOk = 0;
}
?>
<br>
<?php
// Check file size
if ($_FILES["fileToUpload"]["size"] > 5000000) {
    echo "Sorry, your file is too large.";
    $uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" && $imageFileType != "txt") {
    echo "Sorry, only JPG, JPEG, PNG, GIF and TXT files are allowed.";
    $uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    echo "your file was not uploaded correctly. Please try again or contact support!.";
// if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
        echo "Your file has been uploaded
        <br><br><br><br>
         <img src='uploads/$file'>";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
}
?>
</center>
  • 写回答

1条回答 默认 最新

  • duanlin1931 2015-07-21 22:53
    关注

    Short answer: yes, it's possible.

    Real answer: you probably shouldn't. Serving files from MySQL is 5-10x slower than serving static files from the filesystem with most web servers (like Apache, Nginx, etc).

    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号