Jump to content


image upload

  • Please log in to reply
2 replies to this topic

#1 chico1st

  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 08 August 2006 - 03:51 AM

OKay im trying to do an image upload, i have echoed all of my variables and they seem right.
here is the form with the upload:

<form action="addNews.php" method="post" enctype="multipart/form-data" name="uploadform">
<td width="246"><input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="userfile" type="file" class="box" id="userfile"></td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value="  Upload  "></td>

and here is the part of the program taht shoudl enter it into my database

        $fileName = $_FILES['userfile']['name'];
        $tmpName  = $_FILES['userfile']['tmp_name'];
        $fileSize = $_FILES['userfile']['size'];
        $fileType = $_FILES['userfile']['type'];

echo "$fileName --- $tmpName --- $fileSize --- $fileType";// debugging

        $fp = fopen($tmpName, 'r');
        $content = fread($fp, $fileSize);
        $content = addslashes($content);

echo "---$content-----------------------------------------------"; //debugging
            $fileName = addslashes($fileName);

echo $fileName;//debugging

        include '../../lib.php';
$dbConn = connect();

        $query = "INSERT INTO 'picture' (`image_ID`, `name`, `type`, `content`, `size`) VALUES (NULL, '$fileName',  '$fileType', '$content', '$fileSize')";

mysql_query($query, $dbConn) or die('Error, file not uploaded');

        echo "File $fileName uploaded";

i always get the:" Error, file not uploaded", i figure it must have something to do with the insert because the variables are good, and the connection to my database i use in many different programs and it works there

Thanks for any help you can give


#2 fenway

  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 08 August 2006 - 04:38 AM

Well, in general, you should be adding mysql_error() to your query failure control path.  However, in this case, I believe the error is being generated because you're quoting your table name as a string literal instead of backticking it (like the column names).
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 chico1st

  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 08 August 2006 - 06:08 AM

your my hero... ive been working on this for hours. ( i took some time off to watch a movie in there too)

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users