0

在以下代码中,我尝试将图像上传到 mySql 数据库:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
</head>
<body>
<?php 
        $hostname = '';
        $username = '';
        $password = '';
        try {
            $dbh = new PDO("mysql:host=$hostname;dbname= abc", $username, $password);
            //echo 'Connected to database';
        }
        catch(PDOException $e)
        {
          echo $e->getMessage();
        }
            if (!$_POST['uploaded']){
            ?>
          <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
              <p><select name="category">
                     <option value="non">Select category</option>
                     <option value="cars">Cars</option>
                     <option value="real">Real estate</option>
                     <option value="services">Services</option>
                     <option value="electronics">Electronics</option>
                     <option value="furniture">Furniture</option>
                     <option value="home">Home appliance</option>
                     <option value="outdoor">Outdoor</option>
              </select></p>
              <p>Title <br /><input class="tb10" type="text" name="title" /></p>
              <p>Price <br /><input class="tb10" type="text" name="price" /></p>
              <p>Type<br /><select name="type">
                     <option value="non">Select type</option>
                     <option value="offer">Offer</option>
                     <option value="want">Want</option>
              </select><br /></p>
              <p>Description <br />
              <textarea name="description" rows="5" cols="60"></textarea></p>
              <p>Upload pictures<br /><input type="file" name="pictures1"/><br /><input type="file" name="pictures2"/><br /><input type="file" name="pictures3"/><br /><input type="file" name="pictures4"/></p>
              <p>Email <br /><input class="tb10" type="text" id="email1" name="email1" onkeyup="Twitter.updateUrl(this.value)"/><span id="msgbox" style="display:none"></p></span><div id="status1"></div></p>
              <p>Phone <br /><input class="tb10" type="text" name="phone" /></p>
              <p>Address <br /><input class="tb10" type="text" name="address" /></p><br /><br />
              <input type="submit" value="Submit" name="uploaded" class="button" />
            </form>
            <?php 
            }else{
$ip=$REMOTE_ADDR; 
copy($pictures1, "./temporary/".$ip."");
copy($pictures2, "./temporary/".$ip."");
copy($pictures3, "./temporary/".$ip."");
copy($pictures4, "./temporary/".$ip."");
$filename1 = "./temporary/".$REMOTE_ADDR; 
$filename2 = "./temporary/".$REMOTE_ADDR; 
$filename3 = "./temporary/".$REMOTE_ADDR; 
$filename4 = "./temporary/".$REMOTE_ADDR; 
$fp1 = fopen($filename1, "r");
$fp2 = fopen($filename2, "r");
$fp3 = fopen($filename3, "r");
$fp4 = fopen($filename4, "r");
$contents1 = fread($fp1, filesize($filename1)); 
$contents2 = fread($fp2, filesize($filename2)); 
$contents3 = fread($fp3, filesize($filename3)); 
$contents4 = fread($fp4, filesize($filename4));
fclose($fp1); 
fclose($fp2); 
fclose($fp3); 
fclose($fp4);  
$encoded1 = chunk_split(base64_encode($contents1));  
$encoded2 = chunk_split(base64_encode($contents2));  
$encoded3 = chunk_split(base64_encode($contents3));  
$encoded4 = chunk_split(base64_encode($contents4));  
$category = $_POST['category'];
$title = $_POST['title'];
$price = $_POST['price'];
$type = $_POST['type'];
$description = $_POST['description'];
$email1 = $_POST['email1'];
$phone = $_POST['phone'];
$address = $_POST['address'];
$query_insert_user = "INSERT INTO `adtable` ( `Category`, `Title`, `Price`, `Type`, `Description`, `Img1`,`Data1`,`Img2`,`Data2`,`Img3`,`Data3`,`Img4`,`Data4`,`Email`, `Phone`, `Address`) VALUES ( '$category', '$title', '$price', '$type', '$description', 'NULL', '$encoded1', 'NULL', '$encoded2','NULL', '$encoded3','NULL', '$encoded4', '$email1', '$phone', '$address')";
$result_insert_user = mysqli_query($dbh, $query_insert_user);
if (!$result_insert_user) {
echo 'Query Failed ';
}
unlink($filename1); 
unlink($filename2); 
unlink($filename3); 
unlink($filename4); 
} 
?>
</body>
</html>

我希望用户上传 4 张图片。我寻找解决此问题的方法,但找不到任何东西。

我得到的错误是:

Parse error: syntax error, unexpected T_VARIABLE in /home/a6395791/public_html/friendscave/PostAD.php on line

这条线是

$filename2 = "./temporary/".$REMOTE_ADDR; 

谢谢

4

0 回答 0