所以我有这个代码可以上传图像并调整它的大小,并保存两者
if(isset($_POST['submit']))
{
$sql="SELECT MAX(event_id) AS event_id FROM evenimente";
//$result=mysql_query($sql);
$prefix=mysql_query($sql);
$file=$_FILES['image']['tmp_name'];
$file2=$_FILES['image']['tmp_name'];
$image= addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name= addslashes($_FILES['image']['name']);
//
$sizes = array();
$sizes['100'] = 100;
list(,,$type) = getimagesize($_FILES['image']['tmp_name']);
$type = image_type_to_extension($type);
move_uploaded_file($_FILES['image']['tmp_name'], 'images/'.$prefix.$type);
$t = 'imagecreatefrom'.$type;
$t = str_replace('.','',$t);
$img = $t('images/'.$prefix.$type);
foreach($sizes as $k=>$v)
{
$width = imagesx( $img );
$height = imagesy( $img );
$new_width = $v;
$new_height = floor( $height * ( $v / $width ) );
$tmp_img = imagecreatetruecolor( $new_width, $new_height );
imagealphablending( $tmp_img, false );
imagesavealpha( $tmp_img, true );
imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
$c = 'image'.$type;
$c = str_replace('.','',$c);
$c( $tmp_img, 'images/th/'.$prefix.$type );
}
$location="images/" . $prefix.$type;
$sql="INSERT INTO evenimente (event_data, event_datasf, event_titlu, event_detalii, event_poza) VALUES ('". $_POST['data'] ."', '". $_POST['datasf'] ."', '". $_POST['titlu'] ."', '". $_POST['detalii'] ."', '$location') ";
mysql_query($sql);
//$prefix =mysql_insert_id();
include 'include.html';
echo 'OK!!!<br /> Redirecting';
echo "<meta http-equiv='refresh' content='1;adauga_eveniment.php'>";
}
}
所以代码“有效”......我有这个问题,我需要保存图像the event_id
。但我无法$prefix
记住我数据库中的最大 ID,我不知道为什么......希望你能理解。我不能使用mysql_insert_id();
,因为 id 是在 aql 提交之后生成的,并且我需要在那之前的前缀......并且MAX
不起作用......我正在使用event_id
as 主键......
干杯