2012-08-28 46 views
0

我想簡單地將使用圖片上傳的PHP文件夾中的圖像,但它不能正常工作,請幫助我什麼是它的問題..感謝名單:)圖片上傳代碼心不是工作

這是我對setup.php

<?php include("../includes/config.php"); ?> 
<?php 
    if ($_SESSION["isadmin"]) 
    { 

     $con=mysql_connect($dbserver,$dbusername,$dbpassword); 
     if (!$con) { die('Could not connect: ' . mysql_error()); } 

     mysql_select_db($dbname, $con); 

     $result = mysql_query("SELECT * FROM setup WHERE (id=".$_SESSION["id"].")"); 
     while($row = mysql_fetch_array($result)) 
     { 
      $title = $row['title']; 
      $theme = $row['theme']; 
     } 
     mysql_close($con); 
?> 
<!DOCTYPE HTML> 
<html> 
<head> 
    <title>Admdin Home</title> 
    <link rel="StyleSheet" href="css/style.css" type="text/css" media="screen"> 
</head> 
<body> 
    <?php include("includes/header.php"); ?> 
    <?php include("includes/nav.php"); ?> 
    <?php include("includes/aside.php"); ?> 
    <div id="maincontent"> 

     <div id="breadcrumbs"> 
      <a href="">Home</a> > 
      <a href="">Setup</a> > 
      Customization 
     </div> 
     <h2>Customize</h2> 
     <?php 
      if (isset($_GET["status"])) 
      { 
       if($_GET["status"]==1) 
       { 
        echo("<strong>Customization Done!</strong>"); 
       } 
       if($_GET["status"]==2) 
       { 
        echo("<strong>Customization Error!!</strong>"); 
       } 
      } 
     ?> 
     <form method="post" action="setup-action.php" enctype="multipart/form-data" > 
      <label>Title Of Your Organization:</label> <input type="text" name="title" value="<?  php echo $title; ?>" /> <br /> <br /> 
      <label>Select Theme</label> 
      <select name="theme" value="<?php echo $theme; ?>"> 
       <option value="Default">Default</option> 
       <option value="Dark">Dark</option> 
       <option value="White">White</option> 
      </select> 
      <br /> <br /> 
      <label>Choose Your Logo Here</label><input type="file" name="file"/><br /> <br />  
      <input type="submit" name="Upload" value="Upload" /> 
     </form> 
    </div> 

</body> 
<?php include("includes/footer.php"); ?> 
</html> 
<?php 
    } 
    else 
    { 
     header("Location: ".$fullpath."login/unauthorized.php"); 
    } 
?> 

這個代碼是setup-action.php

<?php include("../includes/config.php");?> 
<?php 
if(isset($_FILES["file"])) 
{ 
    if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] ==  "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) 
    && ($_FILES["file"]["size"] < 1000000)) 
    { 
     if ($_FILES["file"]["error"] > 0) 
     { 
      echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; 
     } 

     if (file_exists("../graphics/" . $_FILES["file"]["name"])) 
     { 
      echo $_FILES["file"]["name"] . " already exists. "; 
     } 
     else 
     { 
      move_uploaded_file($_FILES["file"]["name"], "../graphics/" . $_FILES["file"]["name"]); 
      echo "Stored in: " . "../graphics/" . $_FILES["file"]["name"]; 
     } 
    } 
} 
else 
{ 
    echo "Invalid file"; 
} 
?> 
<?php 
    $title=$_POST["title"]; 
    $theme=$_POST["theme"]; 
    $con=mysql_connect($dbserver,$dbusername,$dbpassword); 
    if (!$con) { die('Could not connect: ' . mysql_error()); } 

    mysql_select_db($dbname, $con); 
    $result=mysql_query("SELECT * FROM setup WHERE id=".$_SESSION['id']); 
    $num_rows = mysql_num_rows($result); 
    if ($num_rows > 0) 
    { 
     { 
      mysql_query("UPDATE setup SET title='".$title."' , theme='".$theme."'WHERE  id=".$_SESSION['id']); 
      header("Location:setup.php?status=1"); 
     } 
    } 
    else { 
     header("Location:setup.php?status=2"); 
    } 
    mysql_close($con); 
?> 
+0

您收到了哪些錯誤? –

+0

它沒有給出任何錯誤,其他代碼正在工作作爲即時通過自定義我的網頁通過此代碼,evrything工作完美,除了圖片上傳,請告訴我,我的代碼是否錯誤或什麼問題...我想我已經使用了代碼不正確 –

+0

你從PHP獲得什麼輸出?那裏有很多回聲陳述。你根本沒有輸出嗎? – andrewsi

回答

3

我不能完全肯定這一點,但我認爲你需要移動使用tmp_name的值_uploaded_file,因爲該文件接收到臨時名稱和位置,直到移動。

像這樣:

move_uploaded_file($_FILES["file"]["tmp_name"],"your/path/".$_FILES["file"]["name"]); 

希望工程......其他的一切似乎完全可以給我。

0

需要在move_uploaded_file()函數中使用上傳文件的臨時名稱。臨時名稱包含保存在臨時存儲中的文件的路徑