2012-02-04 63 views
0

我目前正在爲我的教員開發學生數據庫系統。我正在使用PHP和MySQL一起。我正在考慮爲學生上傳他們的個人資料照片創建一個選項,但我找不到任何適當的說明或教程。爲學生數據庫實施個人資料照片上傳

下面的代碼在處理文件上傳:

<?php 
/* Script name: uploadFile.php 
    * Description: Uploads a file via HTTP with a POST form. 
    */ 
    if(!isset($_POST[‘Upload’])) 
    { 
    include(「form_upload.inc」); 
    } 
    else 
    { 
    if($_FILES[‘pix’][‘tmp_name’] == 「none」) 
    { 
     echo 「<p style=’font-weight: bold’> 
     File did not successfully upload. Check the 
      file size. File must be less than 500K.</p>」; 
     include(「form_upload.inc」); 
     exit(); 
    } 
    if(!ereg(「image」,$_FILES[‘pix’][‘type’])) 
    { 
     echo 「<p style=’font-weight: bold’> 
     File is not a picture. Please try another 
      file.</p>」; 
     include(「form_upload.inc」); 
     exit(); 
    } 
    else 
    { 
     $destination=’c:\data’.」\\」.$_FILES[‘pix’][‘name’]; 
     $temp_file = $_FILES[‘pix’][‘tmp_name’]; 
     move_uploaded_file($temp_file,$destination); 
     echo 「<p style=’font-weight: bold’> 
     The file has successfully uploaded: 
      {$_FILES[‘pix’][‘name’]} 
      ({$_FILES[‘pix’][‘size’]})</p>」; 
    } 
    } 
?> 

代碼的文件上傳表單:

<!-- Program Name: form_upload.inc 
    Description: Displays a form to upload a file --> 
<html> 
<head><title>File Upload</title></head> 
<body> 
<ol><li>Enter the file name of the product picture you 
     want to upload or use the browse button 
     to navigate to the picture file.</li> 
    <li>When the path to the picture file shows in the 
     text field, click the Upload Picture 
     button.</li> 
</ol> 
<div align=」center」><hr /> 
<form enctype=」multipart/form-data」 
     action=」uploadFile.php」 method=」POST」> 
    <input type=」hidden」 name=」MAX_FILE_SIZE」 
     value=」500000」 /> 
    <input type=」file」 name=」pix」 size=」60」 /> 
    <p><input type=」submit」 name=」Upload」 
     value=」Upload Picture」 /> 
</form> 
</div></body></html> 

我,我無法找到該文件相同的結果是正在上傳,這是沒有被上傳到該位置,因爲它應該是。

回答

0

你應該改變目的地:

$destination=’c:\data’.」\」.$_FILES[‘pix’][‘name’]; 

或者,如果這是不工作,嘗試移動到某處上傳文件腳本路徑附近,如:

$destination= dirname(__FILE__).DIRECTORY_SEPARATOR.$_FILES[‘pix’][‘name’]; 

如果第二個那麼作品就意味着,你已經給出了錯誤的上傳目錄。

0

我認爲你應該先改變你的圖像路徑。 並且你的數據類型設置爲在mysql中手動創建映像, 它會完成。

+0

如何手動將數據類型設置爲MySQL映像? – Steve87 2012-02-04 15:06:55

0

你有任何錯誤消息嗎? PHP用戶是否有權限上傳目錄?

而且,這裏的兩個務必可能不相關的問題:

  • 不要在任何新代碼使用eregi。它已被棄用,這意味着它將在未來版本的PHP中被刪除。相反,請使用preg_函數,或者在這種情況下使用strpos。
  • 爲什麼$_FILES[‘pix’][‘tmp_name’]曾經是字符串「none」?
+0

「找不到 在此服務器上未找到請求的URL/Mentor Mentee System /?loadload.php。 – Steve87 2012-02-05 06:41:54

+0

您的HTML文件中可能有錯誤的引號字符。確保你使用'「(ASCII碼34)。 – 2012-02-05 14:39:12

相關問題