0

我在使用表单上传图片时遇到问题。这是我的表单代码:

<?php

    echo '<table width="70%">';
    echo '<tr>';
    echo '<td>Add Promotion</td>';
    echo '</tr>';

echo "<form action='addpromotion_post.php' method='post' enctype='multipart/form-data' name='form1' id='form1'>";


echo '<tr>';
echo "<td>&nbsp;</td>";
echo '</tr>';



echo '<tr>';
echo "<td>Promotion :</td>";
echo "<td><textarea name='promotion1' rows='2'></textarea></td>";
echo '</tr>';

echo '<tr>';
echo "<td>Valid From :</td>";
echo "<td><input type='text' size='40' name='validfrom1' value='promotion' /></td>";
echo '</tr>';



echo '<tr>';
echo "<td>Add Picture :</td>";
echo "<td><input type='file' name='pic1' id='pic1' /></td>";
echo '</tr>';

echo '<tr>';
echo "<td>Add Picture :</td>";
echo "<td><input type='file' name='pic2' id='pic2' /></td>";
echo '</tr>';

echo '<tr>';
echo "<td>Add Picture :</td>";
echo "<td><input type='file' name='pic3' id='pic3' /></td>";
echo '</tr>';


echo '<tr>';
echo "<td>&nbsp;</td>";
echo '</tr>';



echo'<tr>
<td colspan="3" align="center"><input type="submit" name="button" id="button" value="Submit"  /></td>
</tr>
</table>
</form>';

这是我的邮政编码:

<?php


    //session_start();
    include_once("connection.php");



    $promotion= $_POST["promotion1"];
    $validfrom= $_POST["validfrom1"];


    $promotion= mysql_real_escape_string($promotion);
    $validfrom= mysql_real_escape_string($validfrom);






    $sql = "insert into promotion(proid, promotion, validfrom) values ('', '$promotion', '$validfrom')";

mysql_query($sql) or die ("Error in query: $sql");

$lastid=mysql_insert_id();






$file = "slider_imagesClient/".$lastid."/";
mkdir($file);



 $pic1 = $_FILES['pic1']['name'];
 $pic2 = $_FILES['pic2']['name'];
 $pic3 = $_FILES['pic3']['name'];

 print_r($pic1);


 $ext1 = pathinfo($pic1,PATHINFO_EXTENSION);
 $ext2 = pathinfo($pic2,PATHINFO_EXTENSION);
 $ext3 = pathinfo($pic3,PATHINFO_EXTENSION);


 //$fileEnote = $_FILES['eNote']['name'];

$path1 = $file.$pic1.'.'.$ext1;
$path2 = $file.$pic2.'.'.$ext2;
$path3 = $file.$pic3.'.'.$ext3;

print_r($path1);


$ory1 = $sfish.$pic1.'.'.$ext1;
$ory2 = $sfish.$pic2.'.'.$ext2;
$ory3 = $sfish.$pic3.'.'.$ext3;


if (!file_exists($path1))
{
 move_uploaded_file ($_FILES['pic1']['tmp_name'], $path1) or die ("Error");
 }

if (!file_exists($path2))
{
 move_uploaded_file ($_FILES['pic2']['tmp_name'], $path2) or die ("Error");
 } 

if (!file_exists($path3))
{
 move_uploaded_file ($_FILES['pic3']['tmp_name'], $path3) or die ("Error");
 }

 if(!empty($pic1)) {
  $sql5= "INSERT INTO pimage (id, proid, image)
            VALUES ('', $lastid, '$ory1')";

  mysql_query($sql5) or die ("Error in query: $sql5");
}
else
{
$not = "not good";
print_r($not);
}

if(!empty($pic2)) {
  $sql5= "INSERT INTO image (resID, image)
            VALUES ($lastid, '$ory2')";

  mysql_query($sql5) or die ("Error in query: $sql5");
}
else
{
$not = "not good";
print_r($not);
}

if(!empty($pic3)) {
  $sql5= "INSERT INTO image (resID, image)
            VALUES ($lastid, '$ory3')";

  mysql_query($sql5) or die ("Error in query: $sql5");
}
else
{
$not = "not good";
print_r($not);
}



?>

print_r($pic1) 没有输出任何东西。print_r($path1) 只是输出slider_imagesClient/50/。

我该如何解决这个问题?我怀疑表格中有错误,但我找不到任何错误。非常感谢:D。非常感谢您的帮助。

4

1 回答 1

0
  echo '<table width="70%">';
  echo '<tr>';
  echo '<td>Add Promotion</td>';
  echo '</tr>';

echo "<form action='addpromotion_post.php' method='post'
 enctype='multipart/form-data' name='form1' id='form1'>";

像这样改变

echo "<form action='addpromotion_post.php' method='post' enctype='multipart/form-data' name='form1' id='form1'>";
    echo '<table width="70%">';
    echo '<tr>';
    echo '<td>Add Promotion</td>';
    echo '</tr>';
于 2012-12-10T09:07:36.900 回答