0
我想qualit = 80添加到我的上傳圖片文件...但沒有成功:(php上傳圖片,我如何爲此代碼添加質量?
那是我的代碼:
<?php
// Set limit image size
$limitFileSize=300000;
// Set thumbnail-height to xxx in pixels
$imageheight=250;
if($peoplef_id=='0'){
$query = "SELECT * FROM peoplef WHERE emailzugang='$emailzugang1' ";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){$peoplef_id=$row['id'];};
}
if($peoplef_id!='0'){
uploadPic("pic1",$peoplef_id,$limitFileSize);
uploadPic("pic2",$peoplef_id,$limitFileSize);
uploadPic("pic3",$peoplef_id,$limitFileSize);
uploadPic("pic4",$peoplef_id,$limitFileSize);
uploadPic("pic5",$peoplef_id,$limitFileSize);
uploadPic("pic6",$peoplef_id,$limitFileSize);
uploadPic("pic7",$peoplef_id,$limitFileSize);
uploadPic("pic8",$peoplef_id,$limitFileSize);
}
function uploadPic($PicName,$itemsID,$limitFileSize)
{
//if($_FILES[$PicName]['size'] > 0 && $_FILES[$PicName]['size'] < $limitFileSize)
//{
if($_FILES[$PicName]['size'] > 0 )
{
$fileName = $_FILES[$PicName]['name'];
$tmpName = $_FILES[$PicName]['tmp_name'];
$fileSize = $_FILES[$PicName]['size'];
$fileType = $_FILES[$PicName]['type'];
$imgsize = GetImageSize($tmpName);
$widthWanted=$imgsize[0];
$heightWanted=$imgsize[1];
/*== check size 0=width, 1=height ==|| ($imgsize[1] > 200) */
if (($imgsize[0] > 650))
{
$widthWanted=2000;
$heightWanted=ceil((1600/$imgsize[0])*$imgsize[1]);
}
echo $widthWanted;
echo "-----";
echo $heightWanted;
$array=array();
echo "<pre>";
$current_file=$tmpName;
$thumb_name="TempUploadImg/".$PicName.$itemsID.".jpg";
exec("convert ".$current_file." -resize $widthWantedx$heightWanted ".$thumb_name, $array);
echo "<br>".print_r($array)."<br>";
echo "</pre>";
$fp = fopen($thumb_name, 'r');
$content = fread($fp, filesize($thumb_name));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
$picnum=$PicName;
$query = "INSERT INTO uploadf (peoplef_id, picnum, name, size, type, content) ".
"VALUES ('$itemsID', '$picnum', '$fileName', '$fileSize', '$fileType', '$content')";
//delete("test.jpg");
mysql_query($query) or die('Error, query failed');
echo "<br>Filee ". basename($fileName). " uploaded<br><br>";
}
//else
//{
/// if($_FILES[$PicName]['size'] > 0){
// $fileName = $_FILES[$PicName]['name'];
// echo "<br><font color=red> File limit Size is $limitFileSize ; canot uploaded $fileName </font><br>";
// }
//}
}
?>
只需粘貼代碼片段,這對於查看問題的人更加相關,特別是如果您的鏈接在以後日期無效 – TommyBs
Tommy謝謝...我試圖添加片段,但它沒有奏效。也許你可以從鏈接添加我的代碼並添加它...? – user1741822
[請不要在新代碼中使用'mysql_ *'函數](http://stackoverflow.com/q/12859942)。它們不再被維護,並且已經開始棄用過程,請參閱[紅盒子](http://php.net/mysql-connect)。請改爲了解[準備好的語句](http://en.wikipedia.org/wiki/Prepared_statement),並使用[PDO](http://php.net/pdo)或[MySQLi](http:// php。淨/ mysqli的); [這篇文章](http://php.net/mysqlinfo.api.choosing)將幫助你決定。如果你選擇PDO,[這裏是一個很好的教程](http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers)。 –