文件路径不会保存在db中

时间:2013-11-11 20:47:59

标签: php mysql sql phpmyadmin

INTRO:我正在创建一个“社交网络”网站。这不仅仅是一项学习活动,也不是一项商业活动。我创建了简单版本的登录和注册(没有加密),他们使用PHPMyadmin并工作。

我已创建表单和php代码以将图像插入/保存到服务器并将路径保存到phpmyadmin(通过sql)。页面打印成功,但路径未出现在数据库中。我已经尝试了数百万,现在我完全卡住了!

<?php
session_start();
$db_conx = $_SESSION['con'];
$id = $_SESSION['uid'];

$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] > 2000)
&& in_array($extension, $allowedExts))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br>";
    echo "Type: " . $_FILES["file"]["type"] . "<br>";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
          $folder="upload/";
          $suffix= rand();
          $path=move_uploaded_file($_FILES["file"]["tmp_name"], $folder . $suffix . $_FILES["file"]["name"]);
          $fullpath = $folder.$suffix.$_FILES["file"]["name"]; 
          echo "Stored in: " .$fullpath;  
          if("INSERT INTO *table* (*field*) VALUES ($fullpath)"){
              echo 'Successfull!!';} else {
        echo 'fail';}
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>

数据库cols database columns

0 个答案:

没有答案