图片无法上传

时间:2012-03-22 21:59:18

标签: php html image

我无法尝试将图片上传到网站,并使用图片地址更新数据库。除图像地址外,所有其他字段都正确地添加到数据库中,并且图像未保存在images文件夹中。我完全不知道什么是错的,当我尝试上传图片时,回复上传文件时出现问题。非常感谢您的帮助。

<?php

 if($_REQUEST['submit'])
 {       
   function isChecked($chkname,$value)
       {
         if(!empty($_POST[$chkname]))
         {
            foreach($_POST[$chkname] as $chkval)
            {
                if($chkval == $value)
                {
                    return true;
                }
            }
          }
          return false;
        }


  $target = "~start/B7/images/";
  $target = $target . basename( $_FILES['photo']['name']);

  $age = $_POST["age"];
  $brand = $_POST["brand"];
  $model = $_POST["model"];
  $price = $_POST["price"];
  $vechicleType = $_POST["vechicleType"];
  $fuelType = $_POST["fuelType"];
  $transmition = $_POST["transmition"];
  $doorsNumbers = $_POST["doorsNumbers"];
  $mileage = $_POST["mileage"];  
  $pic = ($_FILES['photo']['name']);



  //Connect to the server
  $con = mysql_connect("*********", "*********", "*********")
  or die('Could not connect:' . mysql_error());

  // Select database
  mysql_select_db("*********", $con)
  or die('Could not select database');

// Select all the names from the database   
$checkName = mysql_query("SELECT * FROM users");

while ($number = mysql_fetch_array($checkName))
{
  $index = 0;   
  if (($number['user_name'] == $name) && ($number['password'] == $password) 
      || isset($_SESSION['test']))
  {
    $index = 1;
    $_SESSION['test']=$name;
$_SESSION['id']=$number['user_id'];   
   }
 }


  // Select all the names from the database   
  $checkName = mysql_query("SELECT * FROM used_cars");  




 if (!empty($model)) 
  {
    if(isChecked('extras', 'leather'))
       $leather = "yes";


if(isChecked('extras', 'airCon'))
   $airCon = "yes";

if(isChecked('extras', 'satNav'))
   $satNav = "yes";

if(isChecked('extras', 'parkingSensors'))
   $parking = "yes";



$insert1="INSERT INTO used_cars (manufacturer, model, price, image, vehicleType,
age, transmission, fuelType, doorsNumber, user_id, colour, mileage,
leatherSeat, navigatorSystem, parkingSensor, airConditioner) VALUES ('$brand', '$model', '$price', '$pic', '$vechicleType', 
'$age', '$transmition', '$fuelType', '$doorsNumbers', '$user_id', 
'$colour', '$mileage', '$leather', '$satNav', '$parking', '$airCon')";    




     if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
     {
       //Tells you if its all ok
       echo "The file was uploaded";
     }

     else
     {
       //Gives an error if its not
       echo "Sorry, there was a problem uploading your file.";
     }



   }

   else
   {
     echo 'Please fill in all fields';
   }




  mysql_close($con);
  } 
 ?>

1 个答案:

答案 0 :(得分:1)

正如评论中进一步解释的那样,您的路径应该是images/