1

I have a php script, which uploads pictures to a mysql database. The images are taken within the browser. I would like to compress them before uploading, but I'm not quite sure how exactly to compress the uploaded data. What I've got for the moment is this:

if(isset($_FILES['userfile']) && $_FILES['userfile']['size'] > 0)
{
    //$positiony = $_POST['posy'];
    $fileName = $_FILES['userfile']['name'];
    $tmpName  = $_FILES['userfile']['tmp_name'];
    $fp      = fopen($tmpName, 'r');
    $content = fread($fp, filesize($tmpName));
    $content = addslashes($content);
    $content = imagejpeg($content,null,50);
    fclose($fp);
    if(!get_magic_quotes_gpc())
    {
        $fileName = addslashes($fileName);
    }
    $query = "INSERT INTO upload (team_name, id, display, content) ".
    "VALUES ('$team_name', 'null', '1', '$content')";
    mysql_query($query) or die('Error, query failed'.mysql_error()); 

    echo "<br>File $fileName uploaded<br>";
}

The image uploading works fine, but the uploaded images are broken. Introducing imagejpeg as a form of compressing has caused the issues. Should I be using it on something else?

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Oliver
  • 821
  • 5
  • 12
  • 28

1 Answers1

0

Most images are already compressed so there is no need to "compress them further".

Storing them in a database is not a recommended thing to do. Just upload them to a location on the server and save the path to that location.

Sorin Trimbitas
  • 1,467
  • 18
  • 35