上载一张图片,并插入2张具有相同名称,不同大小和不同文件夹的图片
第一个文件夹是user_data,另一个文件夹是mid_image。
我的PHP代码在这里。
function photo_gallery()
{
global $obj;
$image_id1 =$_REQUEST['image_id'];
if($image_id1 ==0)
{
if($_FILES['file']['size'] > 0)
{
$ext = explode('.',$_FILES['file']['name']);
$image_type = $ext[count($ext) - 1];
$img = date('dmYhis').'.'.$image_type;
$image_full_path = (IMAGE_BASE_URL.'/'.$img);
move_uploaded_file($_FILES['file']['tmp_name'],'user_data/'.$img);
$get_image_size = getimagesize('user_data/'.$img);
}
$s=mysql_query("select image_id from photo_gallery ORDER BY image_id DESC");
$r=mysql_fetch_array($s);
$sql_data_array = array('image_name'=>$img,
'image_status'=>$image_status,
'image_type'=>$image_type,
'image_url'=>$image_full_path,
'image_dimensions'=>$get_image_size[0].' x '. $get_image_size[1],
'image_created_date'=>'now()');
$obj->Insert('photo_gallery',$sql_data_array);
$_SESSION['success']="image inserted successfully";
header('location:multiple.php');
}
}
参考方案
将主映像上传到一个根文件夹中,并使用不同的大小两次调用以下函数。希望这可以帮助。
function createThumbs( $pathToImages, $pathToThumbs, $new_height, $new_width, $filename )
{
$info = pathinfo($pathToImages . $filename);
if ( strtolower($info['extension']) == 'jpg' )
$img = imagecreatefromjpeg( "{$pathToImages}" );
if ( strtolower($info['extension']) == 'gif' )
$img = imagecreatefromgif( "{$pathToImages}" );
if ( strtolower($info['extension']) == 'png' )
$img = imagecreatefrompng( "{$pathToImages}" );
$width = imagesx( $img );
$height = imagesy( $img );
$tmp_img = imagecreatetruecolor( $new_width, $new_height );
imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
if ( strtolower($info['extension']) == 'jpg' )
imagejpeg( $tmp_img, "{$pathToThumbs}{$filename}" );
if ( strtolower($info['extension']) == 'gif' )
imagegif( $tmp_img, "{$pathToThumbs}{$filename}" );
if ( strtolower($info['extension']) == 'png' )
imagepng( $tmp_img, "{$pathToThumbs}{$filename}" );
}
谢谢。
执行onclick时获得意外令牌 - javascript我正在使用onclick事件从PHP调用JS函数。这是我的代码:我在一个函数中,因此我需要通过PHP来完成它,因为然后我会返回:$html = '<input type="checkbox" checked value="1" id="setGetSku" name="se…
Javascript到PHP的转换 - javascript我有一个libphonenumber软件包的javascript端口,它具有以下功能:function cleanPhone(a){ a=a.replace(/[^\d\+]/g,""); return a="+"==a.substr(0,1)?"+"+a.replace(/[^\d]/g,…
如何在没有for循环的情况下在Javascript中使用Django模板标签 - javascript我想在JavaScript中使用模板变量:我的问题是在javascript代码中使用for循环,for循环之间的所有事情都会重复..但我不想要....下面粘贴了我的代码..有人可以告诉我更好的方法吗这..因为这看起来很丑..这是我的代码: {% block extra_javascript %} <script src="/static/js…
使用JS和PHP更改弹出窗口背景图像 - javascript我有一个JS函数:function zoom(now) { document.getElementById("popup").style.display = "block"; document.getElementById("photos").style.backgroundImage = …
打印二维阵列 - javascript我正在尝试打印子元素。在this example之后。怎么做?。$myarray = array("DO"=>array('IDEAS','BRANDS','CREATIVE','CAMPAIGNS'), "JOCKEY"=>a…