Jump to content

image upload


chico1st

Recommended Posts

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

<form action="addNews.php" method="post" enctype="multipart/form-data" name="uploadform">
<table>
<tr>
<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>
</tr>
</table>
</form>


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

<?php
if(isset($_POST['upload']))
{
        $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);
        fclose($fp);


echo "---$content-----------------------------------------------"; //debugging
       
        if(!get_magic_quotes_gpc())
        {
            $fileName = addslashes($fileName);
        }
       

echo $fileName;//debugging

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

        [b]$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');[/b]

       
        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

THANKS!
Link to comment
Share on other sites

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).
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.