Jump to content

Upload image and store url in database


craigeves

Recommended Posts

Hi

 

I wonder if someone can help?

 

I want to upload an image to my server - then store the URL in my database table ' gallery'.

 

Upload part works perfect... it's just the storing of the URL in the table that stores a blank entry. Can someone see where im going wrong?

 

Thanks

 

Craig

 

<?php require_once('../Connections/hairstation.php'); 
mysql_select_db($database_hairstation, $hairstation);
$query_gallery = "SELECT * FROM gallery";
$gallery = mysql_query($query_gallery, $hairstation) or die(mysql_error());
$row_gallery = mysql_fetch_assoc($gallery);
$totalRows_gallery = mysql_num_rows($gallery);

?>

<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
  {
  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
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
   //Writes the information to the database
      mysql_query("INSERT INTO `gallery` (file) VALUES ('$file')")
      or die(mysql_error());  
      }
    }
  }
else
  {
  echo "Invalid file";
  }
  


?> 

Link to comment
https://forums.phpfreaks.com/topic/196583-upload-image-and-store-url-in-database/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.