上传图片无法使用foreach运行查询

时间:2013-11-27 15:54:38

标签: php

我在一个意想不到的问题上受到了打扰。我有很多关于创建和插入的问题。

例如:

if (isset($_POST['install']))
{
$install_queries[] = "CREATE TABLE..............";


$install_queries[] = "CREATE TABLE..............";


$install_queries[] = "CREATE TABLE..............";

$allowedExtss = array("jpg", "jpeg", "png");
$extensions = end(explode(".", $_FILES["path2"]["name"]));
//echo $extension;
if (($extensions == "jpeg")|| ($extensions == "jpg")|| ($extensions == "png"))
{
  if ($_FILES["path2"]["error"] > 0)
   {
         $msgs = $_FILES["path2"]["error"] . "<br />";
   }
  else
   {
             move_uploaded_file($_FILES["path2"]["tmp_name"],
     "../images/" . $_FILES["path2"]["name"]);
   }

$filename2 = "images/" . $_FILES["path2"]["name"]; }

  $install_queries[] = "INSERT INTO TABLE(image) VALUES('$filename2')";

 foreach ($install_queries as $q)
 {
  //running queries here
 }

但是在修复脚本时,它会在图像文件中插入空白..但是其他字段已填满...............

由于

1 个答案:

答案 0 :(得分:0)

是否上传任何图片?

如果上传成功,可能只会插入到图像表中。

if (isset($_POST['install']))
{
$install_queries[] = "CREATE TABLE..............";


$install_queries[] = "CREATE TABLE..............";


$install_queries[] = "CREATE TABLE..............";

$allowedExtss = array("jpg", "jpeg", "png");
$extensions = end(explode(".", $_FILES["path2"]["name"]));
//echo $extension;
if (($extensions == "jpeg")|| ($extensions == "jpg")|| ($extensions == "png"))
{
  if ($_FILES["path2"]["error"] > 0)
   {
         $msgs = $_FILES["path2"]["error"] . "<br />";
   }
  else
   {
         if(move_uploaded_file($_FILES["path2"]["tmp_name"],
         "../images/" . $_FILES["path2"]["name"])) {

            $filename2 = "images/" . $_FILES["path2"]["name"];

            $install_queries[] = "INSERT INTO `image` VALUES('$filename2')";
         }
   }

 foreach ($install_queries as $q)
 {
  //running queries here
 }