I have this broken php upload script

Posted by Anders Kitson on Stack Overflow See other posts from Stack Overflow or by Anders Kitson
Published on 2010-05-25T04:52:53Z Indexed on 2010/05/25 5:01 UTC
Read the original article Hit count: 257

Filed under:
|
|

I have this script for uploading a image and content from a form, it works in one project but not the other. I have spent a good few hours trying to debug it, I am hoping someone could point out the issue I might be having. Where there are comments is where I have tried to debug. The first error I got was the "echo invalid file" at the beginning of the last comment. With these specific areas commented out the upload name and type that I am supposed to be grabbing from the form is not being echoed, I am thinking this is where the error is occurring, but can't quite seem to find it. Thanks.

    <?php
include("../includes/connect.php");
/*
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 2000000))
  {
    */
  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 />";

        /* GRAB FORM DATA */
    $title = $_POST['title'];
    $date = $_POST['date'];
    $content = $_POST['content'];
    $imageName1 = $_FILES["file"]["name"];

    echo $title;
    echo "<br/>";
    echo $date;
    echo "<br/>";
    echo $content;
    echo "<br/>";
    echo $imageName1;

    $sql = "INSERT INTO blog (title,date,content,image)VALUES(
    \"$title\",
    \"$date\",
    \"$content\",
    \"$imageName1\"
    )";

    $results = mysql_query($sql)or die(mysql_error());

    echo "<br/>";


    if (file_exists("../images/blog/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "../images/blog/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "../images/blog/" . $_FILES["file"]["name"];
      }
    }

  /*
  }
else
  {
  echo "Invalid file" . "<br/>";
  echo "Type: " . $_FILES["file"]["type"] . "<br />";
  }
  */

  //lets create a thumbnail of this uploaded image.
  /*
    $fileName = $_FILES["file"]["name"];
    createThumb($fileName,310,"../images/blog/thumbs/");
    function createThumb($thisFileName, $thisThumbWidth, $thisThumbDest){
    $thisOriginalFilePath = "../images/blog/". $thisFileName;
    list($width, $height) = getimagesize($thisOriginalFilePath);
    $imgRatio =$width/$height;
    $thisThumbHeight = $thisThumbWidth/$imgRatio;
    $thumb = imagecreatetruecolor($thisThumbWidth,$thisThumbHeight);
    $source = imagecreatefromjpeg($thisOriginalFilePath);
    imagecopyresampled($thumb, $source, 0, 0, 0, 0, $thisThumbWidth,$thisThumbHeight, $width, $height);
    $newFileName = $thisThumbDest.$thisFileName;
    imagejpeg($thumb,$newFileName, 80);
    echo "<p><img src=\"$newFileName\" /></p>";

    //header("location: http://www.google.ca");

    }

    */





?>

© Stack Overflow or respective owner

Related posts about php

Related posts about image