我有一个php脚本,它将图片上传到mysql数据库。图像是在浏览器中拍摄的。我想在上传之前压缩它们,但我不太确定如何压缩上传的数据。我现在得到的是:
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>";
}
图片上传工作正常,但上传的图片已损坏。引入imagejpeg
作为一种压缩形式导致了这些问题。我应该在其他地方使用它吗?