2013-11-26 18 views
0

我對上傳和數據庫有一些問題。我上傳文件(abc.txt)並且文件已經插入文件夾名稱(上傳)。但是,當我檢查數據庫(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> 

希望任何人都可以幫助我,謝謝。

+0

你有什麼迄今所做調試這個? – CBroe

+0

我已經檢查數據庫和php代碼。 – nazerol

+0

白色什麼結果?那麼「檢查」是什麼意思?首先,刪除'error_reporting(0)'。然後實現一些mysql錯誤處理。如果你不知道如何,請查看它! – CBroe

回答

0

替換該查詢大概這能解決

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

我已經替換了代碼,但它不起作用。當我檢入數據庫時​​,文件不包含在數據庫中。 – nazerol

相關問題