2013-06-03 59 views
2

我試圖爲我的網站建立一個圖片上傳,我只有以下內容沒有任何輸出,但我的網頁呈現好嗎?任何人都可以看到我可能會錯誤\PHP文件上傳不起作用,注意輸出到瀏覽器

//if they DID upload a file... 
if($_FILES['profile_image']['name']) 
{ 
    //if no errors... 
    if(!$_FILES['profile_image']['error']) 
    { 
     //now is the time to modify the future file name and validate the file 
     $new_file_name = strtolower($_FILES['profile_image']['tmp_name']); //rename file 
     if($_FILES['profile_image']['size'] > (1024000)) //can't be larger than 1 MB 
     { 
      $valid_file = false; 
      $message = 'Oops! Your file\'s size is to large.'; 
     } 

     //if the file has passed the test 
     if($valid_file) 
     { 
      //move it to where we want it to be 
      move_uploaded_file($_FILES['profile_image']['tmp_name'], 'uploads/'.$new_file_name); 
      $message = 'Congratulations! Your file was accepted.'; 
     } 
    } 
    //if there is an error... 
    else 
    { 
     //set that to be the returned message 
     $message = 'Ooops! Your upload triggered the following error: '.$_FILES['profile_image']['error']; 
    } 
} 

else { 
echo 'success'; 
    } 

<form method="post" action="./process-signup.php" enctype="multipart/form-data" > 


    <input type="file" class="profile_image text-input" name="profile_image" placeholder="Upload a picture"/><br /> 
    <input type="submit" id="signup-com-btn" value="Complete Signup" /> 

</form> 
+0

我們可以看到代碼的HTML部分嗎? – showdev

+1

開始於'print_r($ _ FILES);' – 2013-06-03 22:03:26

+0

Array([profile_image] => Array([name] => 4.jpg [type] => image/jpeg [tmp_name] =>/tmp/php5MznP2 [error] = > 0 [size] => 119731)) – Liam

回答

1

在你的PHP腳本,你已經賦值的變量$message不同的價值觀,不同的階段,是這樣的:

$message = 'Oops! Your file\'s size is to large.'; 
$message = 'Congratulations! Your file was accepted.'; 
$message = 'Ooops! Your upload triggered the following error: 

但你是不是其實echoing它,所以你沒有得到任何消息。因此,我會建議回顯它,顯然。

+0

我已經試過回顯我的郵件@PHPNOOB,但仍然沒有輸出 – Liam

+0

嗯,問題可能是,'變量作用域'有關。分配值,然後在腳本內部回顯它們,如'echo'哎呀!你的文件的大小很大。';' – samayo