我試圖爲我的網站建立一個圖片上傳,我只有以下內容沒有任何輸出,但我的網頁呈現好嗎?任何人都可以看到我可能會錯誤\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>
我們可以看到代碼的HTML部分嗎? – showdev
開始於'print_r($ _ FILES);' – 2013-06-03 22:03:26
Array([profile_image] => Array([name] => 4.jpg [type] => image/jpeg [tmp_name] =>/tmp/php5MznP2 [error] = > 0 [size] => 119731)) – Liam