2013-06-30 77 views
0

我有一個用戶註冊表格,現在有照片上傳功能。但是,當用戶不經常上傳照片時,我會遇到錯誤。但我希望能夠讓用戶不要上傳照片,如果他們不想。用戶註冊與照片上傳,得到錯誤,當用戶不上傳照片

但是,它仍將所有其他值插入到數據庫中。

ERRORS: 警告:file_get_contents()函數:文件名不能在/mounted-storage/home94c/sub005/sc13306-UHPW/tvproductionguide.com/add.php是空的上線路25

警告:無法修改標頭信息 - 已在/ mounted-storage/home94c/sub005/sc13306中發送的標頭(輸出開始於/mounted-storage/home94c/sub005/sc13306-UHPW/tvproductionguide.com/add.php:25) UHPW/tvproductionguide.com/add.php on line 35

我在PHP中很新,在編碼時可能會犯幾個錯誤(請原諒我的代碼)。

表格很簡單,應該沒問題。我不會在這裏發佈,除非有人需要看到它。 PHP頁面代碼:

<?php include 'configdb.php'; 

$name=$_POST['name']; 
$last_name=$_POST['last_name']; 
$position=$_POST['position']; 
$bio=$_POST['bio']; 
$experience=$_POST['experience']; 
$city=$_POST['city']; 
$phone=$_POST['phone']; 
$email=$_POST['email']; 
$website=$_POST['website']; 

if (!isset($_FILES['image']['tmp_name'])) { 
    echo ""; 
    }else{ 
    $file=$_FILES['image']['tmp_name']; 
    $image= addslashes(file_get_contents($_FILES['image']['tmp_name'])); 
    $image_name= addslashes($_FILES['image']['name']); 

      move_uploaded_file($_FILES["image"]["tmp_name"],"photos/" . $_FILES["image"]["name"]); 

      $photo_location="photos/" . $_FILES["image"]["name"]; 
      $caption=$_POST['caption']; 

      $save=mysql_query("INSERT INTO miamicrew (name, last_name, position, bio, experience, city, phone, email, website, photo_location, caption) VALUES ('$name','$last_name','$position','$bio','$experience','$city','$phone','$email', '$website','$photo_location','$caption')"); 
      header("location: added.php"); 
      exit();     
    } 
?> 
+0

請添加表格 – wgcrouch

回答

1

試試這個,

if (!isset($_POST['image'])) { 
$photo_location=""; 
     $caption=""; 


}else{ 
$file=$_FILES['image']['tmp_name']; 
$image= addslashes(file_get_contents($_FILES['image']['tmp_name'])); 
$image_name= addslashes($_FILES['image']['name']); 

     move_uploaded_file($_FILES["image"]["tmp_name"],"photos/" . $_FILES["image"]["name"]); 

     $photo_location="photos/" . $_FILES["image"]["name"]; 
     $caption=$_POST['caption']; 

     $save=mysql_query("INSERT INTO miamicrew (name, last_name, position, bio, experience, city, phone, email, website, photo_location, caption) VALUES ('$name','$last_name','$position','$bio','$experience','$city','$phone','$email', '$website','$photo_location','$caption')"); 
     header("location: added.php"); 
     exit();     
} 
0

的代碼是凌亂的,完全沒有經過深思熟慮。下面是它應該是什麼樣的效果。

if(strlen($_FILES['image']['tmp_name']) > 0) 
{ 
    $image = addslashes(file_get_contents($_FILES['image']['tmp_name'])); 
    $image_name = addslashes($_FILES['image']['name']); 

    if(move_uploaded_file($_FILES["image"]["tmp_name"], "photos/" . $_FILES["image"]["name"]) { 
     echo "Success"; 
    } else { 
     echo "Error"; 
     exit(); 
    } 

    $photo_location = "photos/" . $_FILES["image"]["name"]; 
} 
else 
{ 
    $photo_location=""; 
    $caption = $_POST['caption']; 
} 


$save = mysql_query("INSERT INTO miamicrew (name, last_name, position, bio, experience, city, phone, email, website, photo_location, caption) VALUES ('$name','$last_name','$position','$bio','$experience','$city','$phone','$email', '$website','$photo_location','$caption')"); 

header("location: added.php"); 
exit();