2014-05-23 73 views
-2

我剛剛做了一個文件上傳代碼,我想知道爲什麼文件上傳不起作用?我檢查了我的圖像文件夾在本地主機的權限,這似乎是好的。我不知道問題到底在哪裏。有任何想法嗎?上傳的圖像不在圖像文件夾中

<?php 

require "config.php"; 
require "functions.php"; 
require "database.php"; 

if(isset($_FILES['fupload'])){ 
    $filename = addslashes($_FILES['fupload']['name']); 
    $source = $_FILES['fupload']['tmp_name']; 
    $target = $path_to_image_directory . $filename; 
    $description = addslashes($_POST['description']); 
    $src = $path_to_image_directory . $filename; 
    $tn_src = $path_to_thumbs_directory . $filename; 

    if (strlen($_POST['description'])<4) 
     $error['description'] = '<p class="alert">Please enter a description for your photo</p>'; 
    if($filename == '' || !preg_match('/[.](jpg)|(gif)|(png)|(jpeg)$/', $filename)) 
     $error['no_file'] = '<p class="alert">Please select an image, dummy! </p>'; 
    if (!isset($error)){ 
     move_uploaded_file($source, $target); 

     $q = "INSERT into photo(description, src, tn_src)VALUES('$description', '$src','$tn_src')"; 
     $result = $mysqli->query($q) or die (mysqli_error($myqli)); 

     if ($result) { 
      echo "Succes! Your file has been uploaded"; 
     } 
     createThumbnail($filename); 
    } 
} 
?><!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <title>Upload</title> 
    <link rel="stylesheet" href="css/styles.css"> 
</head> 
<body> 
    <h1>My photos</h1> 

    <ul><?php getPhotos(); ?></ul> 
    <h2>Upload a photo</h2> 

    <form enctype="multipart/form-data" action="index.php" method="post"> 
     <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> 
     <input type="file" name="fupload" /><br/> 
     <textarea name="description" id="description" cols="50" rows="6"></textarea><br/> 
     <input type="submit" value="Upload photo" name="submit" /> 
    </form> 

    <?php 
    if (isset($error["description"])) { 
     echo $error["description"]; 
    } 

    if (isset($error["no_file"])) { 
     echo $error["no_file"]; 
    } 

    ?> 

</body> 
</html> 
+0

你在窗戶上嗎?是C://上的本地主機? –

+0

嗨,不,我使用OSX。順便說一句,上傳的圖像存儲在數據庫中。我唯一的問題是,圖像不顯示在我的圖像文件夾。 – user2885746

+0

運行Apache/Nginx的用戶是否具有對該文件夾的寫入權限? –

回答

0

請確保您在$ path_to_thumbs_directory中追加目錄分隔符。 而且你不需要使用addslashes到$ filename。

+0

請不要發表評論作爲答覆。 http://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-c​​an-i-do-instead/214174#214174 –

相關問題