Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 上载文件和已上载到文件夹中的文件,但为什么文件未存储在数据库中_Php_Database_File Upload_Upload - Fatal编程技术网

Php 上载文件和已上载到文件夹中的文件,但为什么文件未存储在数据库中

Php 上载文件和已上载到文件夹中的文件,但为什么文件未存储在数据库中,php,database,file-upload,upload,Php,Database,File Upload,Upload,我有一些关于上传和数据库的问题。我上传文件(abc.txt),文件已经插入到文件夹名(uploads)。但当我签入数据库(php)时,它并没有进入。这是我的密码: <?php require_once('Connections/sperformance.php');?> <?php session_start(); if(isset($_SESSION['MM_Username'])) ?> <?php error_reporting(0); if(isset(

我有一些关于上传和数据库的问题。我上传文件(abc.txt),文件已经插入到文件夹名(uploads)。但当我签入数据库(php)时,它并没有进入。这是我的密码:

<?php require_once('Connections/sperformance.php');?>
<?php session_start();
if(isset($_SESSION['MM_Username']))  
?>
<?php
error_reporting(0);
if(isset($_POST['submit']))
{
    $target = "uploads/"; 
    $allowedExts = array("jpg", "jpeg", "png", "doc", "txt", "JPG", "JPEG", "PNG", "DOC", "TXT", "zip");
    $extension = end(explode(".", $_FILES["file_upload"]["name"]));
    $target = $target . basename( $_FILES['file_upload']['name']);
    $date = date("Y-m-d H:i:s");

    //Function to generate image thumbnails
    function make_thumb($src, $dest, $desired_width) {

        /* read the source image */
        $source_image = imagecreatefromjpeg($src);
        $width = imagesx($source_image);
        $height = imagesy($source_image);

        /* find the "desired height" of this thumbnail, relative to the desired width  */
        $desired_height = floor($height * ($desired_width / $width));

        /* create a new, "virtual" image */
        $virtual_image = imagecreatetruecolor($desired_width, $desired_height);

        /* copy source image at a resized size */
        imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);

        /* create the physical thumbnail image to its destination with 100% quality*/
        imagejpeg($virtual_image, $dest,100);
    }

    //check for allowed extensions


if (($_FILES["file_upload"]["type"] == "image/jpg")|| ($_FILES["file_upload"]["type"] == "image/jpeg") || ($_FILES["file_upload"]["type"] == "image/png")|| ($_FILES["file_upload"]["type"] == "application/msword") || ($_FILES["file_upload"]["type"] == "text/plain")  || ($_FILES["file_upload"]["type"] == " application/octet-stream") && in_array($extension, $allowedExts))


    {
        $photoname = $_FILES["file_upload"]["name"];
        if (file_exists("../uploads/" . $photoname))
        {
            die( '<div class="error">Sorry <b>'. $photoname . '</b> already upload before this.</div>');
        }

        if(move_uploaded_file($_FILES['file_upload']['tmp_name'], $target)) 
        {
            $query = "INSERT INTO updown (nama_file,tkh_muatnaik) VALUES ('$photoname','$date')";
            mysql_query($query); 
            $sql = "SELECT MAX(id_file) FROM updown";
            $max = mysql_query($sql);
            $row = mysql_fetch_array($max);
            $maxId = $row['MAX(id_file)'];

            $type = $_FILES["file_upload"]["type"];
            switch($type)
            {
                case "image/jpeg":
                $ext = ".jpeg";
                break;
                case "image/jpg";
                $ext = ".jpg";
                break;  
                case "image/png":
                $ext = ".png";
                break;
                case "application/msword":
                $ext = ".doc";
                break;
                case "text/plain":
                $ext = ".txt";
                break;      
                case "application/octet-stream":
                $ext = ".zip";
                break;      
            }

            if (!in_array($ext, array('.doc', '.txt', '.zip'))) {
            //define arguments for the make_thumb function
            $source = "uploads/".$photoname;
            $destination = "thumbnails/thumb_". $maxId . $ext ."";          
            //specify your desired width for your thumbnails
            $width = "282";
            //Finally call the make_thumb function
            make_thumb($source,$destination,$width);
            }

            $msg = '<div class="success">
                        <br/><b>Uploaded: </b>' . basename($photoname) . '<br />
                        <b>Format: </b>' . $_FILES["file_upload"]["type"] . '<br />
                        <b>Size: </b>' . ceil(($_FILES["file_upload"]["size"] / 1024)) . 'Kb<br />
                    </div>';
            }    
            else
            {
                $msg = '<div class="error">Sorry, Upload file does not work.</div>';
            }
        }
        else
        {
            $msg = '<div class="error">This file format is not accepted!</div>';
        }
}
?>
<?php ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>eportfolio-FCSIT</title>
<style type="text/css"> 
<!-- 
body  {
    font: 100% Verdana, Arial, Helvetica, sans-serif;
    margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
    padding: 0;
    text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
    color: #000000;
    background-color: #CCCCCC;
}

/* Tips for Elastic layouts 
1. Since the elastic layouts overall sizing is based on the user's default fonts size, they are more unpredictable. Used correctly, they are also more accessible for those that need larger fonts size since the line length remains proportionate.
2. Sizing of divs in this layout are based on the 100% font size in the body element. If you decrease the text size overall by using a font-size: 80% on the body element or the #container, remember that the entire layout will downsize proportionately. You may want to increase the widths of the various divs to compensate for this.
3. If font sizing is changed in differing amounts on each div instead of on the overall design (ie: #sidebar1 is given a 70% font size and #mainContent is given an 85% font size), this will proportionately change each of the divs overall size. You may want to adjust based on your final font sizing.
*/
.twoColElsLtHdr #container {
    width: 65%;  /* this width will create a container that will fit in an 800px browser window if text is left at browser default font sizes */
    background: #DBE6F4; /* the auto margins (in conjunction with a width) center the page */
    border: 1px solid #000000;
    text-align: left; /* this overrides the text-align: center on the body element. */
    margin-top: 0;
    margin-right: auto;
    margin-bottom: 0;
    margin-left: auto;
    position: absolute;
    top: 25px;
    left: 232px;
    padding: 10px;
    white-space: normal;
    height: auto;
    bottom: 20px;
    background-color: #DBE6F4;
} 
.twoColElsLtHdr #header {
    top: 70px;
    border: thin solid #DBE6F4;
    background-color: #DBE6F4;
} 
.twoColElsLtHdr #header h1 {
    margin: 0; /* zeroing the margin of the last element in the #header div will avoid margin collapse - an unexplainable space between divs. If the div has a border around it, this is not necessary as that also avoids the margin collapse */
    padding: 10px 0; /* using padding instead of margin will allow you to keep the element away from the edges of the div */
    bottom: 20px;
}

/* Tips for sidebar1:
1. Be aware that if you set a font-size value on this div, the overall width of the div will be adjusted accordingly.
2. Since we are working in ems, it's best not to use padding on the sidebar itself. It will be added to the width for standards compliant browsers creating an unknown actual width. 
3. Space between the side of the div and the elements within it can be created by placing a left and right margin on those elements as seen in the ".twoColElsLtHdr #sidebar1 p" rule.
*/
.twoColElsLtHdr #navigasi {
    float: left;
    width: 228px; /* top and bottom padding create visual space within this div */
    padding-top: 5px;
    padding-bottom: 5px;
    padding-left: 5;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 12px;
    font-style: normal;
    top: 139px;
    position: absolute;
    text-align: justify;
    white-space: nowrap;
    text-indent: -5px;
    height: 155px;
    line-height: normal;
    border: thin none #76BCE2;
    left: 7px;
}
.twoColElsLtHdr #sidebar1 h3, .twoColElsLtHdr #sidebar1 p {
    margin-left: 10px; /* the left and right margin should be given to every element that will be placed in the side columns */
    margin-right: 10px;

}




/* Tips for mainContent:
1. If you give this #mainContent div a font-size value different than the #sidebar1 div, the margins of the #mainContent div will be based on its font-size and the width of the #sidebar1 div will be based on its font-size. You may wish to adjust the values of these divs.
2. The space between the mainContent and sidebar1 is created with the left margin on the mainContent div.  No matter how much content the sidebar1 div contains, the column space will remain. You can remove this left margin if you want the #mainContent div's text to fill the #sidebar1 space when the content in #sidebar1 ends.
3. To avoid float drop, you may need to test to determine the approximate maximum image/element size since this layout is based on the user's font sizing combined with the values you set. However, if the user has their browser font size set lower than normal, less space will be available in the #mainContent div than you may see on testing.
4. In the Internet Explorer Conditional Comment below, the zoom property is used to give the mainContent "hasLayout." This avoids several IE-specific bugs that may occur.
*/
.thrColAbsHdr #sidebar2 {
    position: absolute;
    right: 0;
    width: 160px; /* the actual width of this div, in standards-compliant browsers, or standards mode in Internet Explorer will include the padding and border in addition to the width */
    background: #EBEBEB; /* padding keeps the content of the div away from the edges */
    bottom: 100px;
    border: thin dashed #000000;
}

.twoColElsLtHdr #mainContent {
    left: 86px;
    right: auto;
    margin-top: 0;
    margin-right: 1.5em;
    margin-bottom: 0;
    margin-left: 13em;
    top: 150px;
    bottom: auto;
    padding-bottom: 0px;
    padding-left: 40px;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 12px;
    background-color: #FFFFFF;
    text-align: justify;
    position: absolute;
    width: 609px;
    height: 325px;
    border: thin dashed #76BCE2;
    vertical-align: 20%;
} 
.twoColElsLtHdr #footer {
    background-color: #DDDDDD;
    background-image: url(image/footer.jpg);
    width: 884px;
    padding: 5;
    position: absolute;
    bottom: 5px;
} 
.twoColElsLtHdr #footer p {
    margin: 0; /* padding on this element will create space, just as the the margin would have, without the margin collapse issue */
    bottom: 5px;
    top: 5px;
    padding-top: 5px;
    padding-right: 0;
    padding-bottom: 5px;
    padding-left: 0;
    position: absolute;
}

/* Miscellaneous classes for reuse */
.fltrt { /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
    float: right;
    margin-left: 8px;
}
.fltlft { /* this class can be used to float an element left in your page */
    float: left;
    margin-right: 8px;
}
.clearfloat { /* this class should be placed on a div or break element and should be the final element before the close of a container that should fully contain a float */
    clear:both;
    height:0;
    font-size: 1px;
    line-height: 0px;
}
#apDiv1 {
    position:absolute;
    width:223px;
    height:188px;
    z-index:1;
    left: 10px;
    top: 333px;
    border: thin dashed #76BCE2;
}
#apDiv2 {
    position:absolute;
    width:168px;
    height:115px;
    z-index:1;
    left: 730px;
    top: -181px;
    border: thin dashed #76BCE2;
}
.style3 {color: #0000FF}
#apDiv3 {
    position:absolute;
    width:567px;
    height:195px;
    z-index:1;
    border: thin dashed #76BCE2;
}
--> 
</style>
<!--[if IE]>
<style type="text/css"> 
/* place css fixes for all versions of IE in this conditional comment */
.twoColElsLtHdr #sidebar1 { padding-top: 30px; }
.twoColElsLtHdr #mainContent { zoom: 1; padding-top: 15px; }
/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
</style>
<![endif]-->
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
</head>

<body class="twoColElsLtHdr">

<div id="container">
  <div id="header"><img src="image/header_baru.jpg" width="880" height="123" alt="header" />
  <!-- end #header --></div>
  <div id="navigasi">
 <style>
nav {
    /* Repeating background image */
    background: url(image/Un.png);
    width:215px;
    margin:5px;
}

nav ul {
    /* Removes bullet points */
    list-style:none;
    margin:0;
    padding:0;

}
nav ul li {
    /* Any child positioned absolutely will be positioned relative to this */
    border:thin dashed #76BCE2;
    position:relative;
}
nav a {
    color:#e8e8e8;
    padding:10px 0px;
    /* Fill all available horizontal space */
    display:block;
    /* Remove underline */
    text-decoration:none;
    /* 
    New CSS3 animations:
    apply transition to background property, taking 1s to change it 
    */
    transition:background 1s;
    -moz-transition:background 1s;
    -webkit-transition:background 1s;
    -o-transition:background 1s;
    font-family:arial;
    font-size:12px;
    text-transform:uppercase;
    padding-left:15px;
}
nav a:hover {
    /* 
    RGBA background for transparancy: 
    last number(0.05) is the transparency 
    */
    background: RGBA(255,255,255,0.05);
    color:#fff;

}
nav a:hover span {
    background: #009999;
    transform:rotate(90deg);
    -moz-transform:rotate(90deg);
    -webkit-transform:rotate(90deg);
}
nav ul li:hover ul {
    display:block;
}
nav ul ul {
    position:relative;
    bottom:210px;
    top:0;
    border-top:0px solid #e9e9e9;
    display:none;
}
nav ul ul li {
    width:211px;
    background:#f1f1f1;
    border:1px solid #e9e9e9;
    border-top:0;
}
nav ul ul li a {
    color:#a8a8a8;
    font-size:12px;
    text-transform:none;
}
nav ul ul li a:hover {
    color:#0000FF;
}
nav span {
    width:12px;
    height:12px;
    background:#fff;
    display:inline-block;
    float:left;
    margin-top:3px;
    margin-right:20px;
    position:relative;
    transition:all 0.5s;
    -moz-transition:all 0.5s;
    -o-transition:all 0.5s;
    -webkit-transition:all 0.5s;
}
nav span:before {
    content:"";
    width:12px;
    height:2px;
    background:#76BCE2;
    position:absolute;
    left:0px;
    top:5px;
}
nav span:after {
    content:"";
    width:2px;
    height:12px;
    background:#76BCE2;
    position:absolute;
    left:5px;
    position:top;
}

</style>
<nav><a href="student_home.php"><span></span> Home </a>
  <ul><li> <a href="student_profile.php"><span></span>Profile</a>
                    </li>
        <li> <a href="student_portfolio.php"><span></span>Portfolio </a>

        </li>
    <li> <a href="student_academic.php"><span></span>Academic Performance </a>
        <ul>
                <li><a href="student_feedback.php">Comment / Feedback </a></li></ul>

      </li>
        <li> <a href="stu_logout.php"><span></span>Logout </a>
    </ul>
    </li>
</nav>

  </div>
  <div id="mainContent">
  <p class="style3">Welcome, <?php echo $_SESSION['MM_Username']?>
<h1 align="center">  Upload Portfolio</h1>



   <div id="apDiv3">
   <body>
<table width="86%"  align="center">
<tr>
<td colspan="2" class="header"></td>
</tr>
  <tr>
    <td width="79%"></td>
  </tr>
  <tr>
    <td><H3 class="main_title">Upload file.</H3>
      (<a href="student_download.php" >List File</a>)
      <div id="upload">
<?php echo $msg; ?>
<form action="" method="post" enctype="multipart/form-data">
<br /><label for="file"> File:</label>
<input type="file" name="file_upload" id="upload_file" /><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<input type="submit" name="submit" value="Upload" />
</form>
</div>

  </tr>
</table>
</div>
  </div>
  <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
  <div id="footer">
    <div align="center"><font size="1">
<strong><br />
</strong>Copyright &copy; 2013 FACULTY OF  COMPUTER SCIENCE &amp; INFORMATION TECHNOLOGY( FCSIT).<br />
Universiti Malaysia Sarawak, 94300 Kota Samarahan, Sarawak, Malaysia Telephone: +60 82581000/+60 82581388, Fax: +60 82 665 088&nbsp;<br />
<br>
    </font></div>
  <!-- end #footer --></div>
<!-- end #container --></div>
</body>
</html>

电子版FCSIT
导航{
/*重复背景图像*/
背景:url(image/Un.png);
宽度:215px;
保证金:5px;
}
导航ul{
/*删除项目符号*/
列表样式:无;
保证金:0;
填充:0;
}
李国荣{
/*绝对定位的任何子对象都将相对于此对象定位*/
边框:细虚线#76BCE2;
位置:相对位置;
}
导航a{
颜色:#e8e8e8;
填充:10px 0px;
/*填充所有可用的水平空间*/
显示:块;
/*删除下划线*/
文字装饰:无;
/* 
新的CSS3动画:
将转换应用于背景属性,用1s更改它
*/
过渡:背景1s;
-moz跃迁:背景1s;
-webkit转换:背景1s;
-o-转变:背景1s;
字体系列:arial;
字体大小:12px;
文本转换:大写;
左侧填充:15px;
}
导航a:悬停{
/* 
透明性的RGBA背景:
最后一个数字(0.05)是透明度
*/
背景:RGBA(255255,0.05);
颜色:#fff;
}
导航a:悬停跨度{
背景:#009999;
变换:旋转(90度);
-moz变换:旋转(90度);
-webkit变换:旋转(90度);
}
导航ulli:悬停ul{
显示:块;
}
导航ul{
位置:相对位置;
底部:210px;
排名:0;
边框顶部:0px实心#e9e9e9;
显示:无;
}
李国宝{
宽度:211px;
背景#f1f1;
边框:1px实心#e9e9e9;
边界顶部:0;
}
海军ulli a{
颜色:#a8a8a8;
字体大小:12px;
文本转换:无;
}
导航ulli a:悬停{
颜色:#0000FF;
}
导航跨度{
宽度:12px;
高度:12px;
背景:#fff;
显示:内联块;
浮动:左;
利润上限:3倍;
右边距:20px;
位置:相对位置;
过渡:均为0.5s;
-moz转换:所有0.5s;
-o型过渡:均为0.5s;
-webkit过渡:所有0.5s;
}
导航跨度:之前{
内容:“;
宽度:12px;
高度:2倍;
背景:#76BCE2;
位置:绝对位置;
左:0px;
顶部:5px;
}
导航跨度:后{
内容:“;
宽度:2倍;
高度:12px;
背景:#76BCE2;
位置:绝对位置;
左:5px;
位置:顶部;
}

欢迎光临, 上传公文包 上传文件。 ()
文件:


版权与复制;2013年计算机科学与技术学院;信息技术(FCSIT)。
马来西亚沙捞越大学,94300科塔萨马拉汉,沙捞越,马来西亚电话:+6082581000/+6082581388,传真:+6082665088


希望任何人都能帮助我。谢谢。

用此替换您的查询可能这会解决问题

$query = "INSERT INTO updown (nama_file,tkh_muatnaik) 
VALUES (\"".$photoname."\",".$date.")";
mysql_query($query);

我已经替换了代码,但它不起作用。当我签入数据库时,该文件并没有包含在数据库中。到目前为止,您做了什么来调试它?我已经签入了数据库,并且只签入了php代码。结果如何?“支票”到底是什么意思?首先,删除
错误报告(0)
。然后实现一些mysql错误处理。如果你不知道怎么做,就去查吧!