为什么接不到高和宽的值
<?php
header("Content-type:image/jpeg");
?>
<?php
class picture{
function ResizeImage($filename){
list($width, $height) = getimagesize($filename);
$new_width =300;
$new_height =300;
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0,0,0,0,$new_width, $new_height,$width,$height);
imagejpeg($image_p);
return $image;
//return imagejpeg($image_p);
}
}
?> 这是缩略图的功能单独运行可以实现,但是下面的代码调用上面的方法就得不到宽和高的值 $image值也没空 请教一下各位高手啊!!!万分感谢!!!
<?php
include_once('sleditor.php');
$upok=1;
if($upok){
$file=($_FILES['photofile']['name']);
$file_name = ($_FILES['photofile']['tmp_name']);
$picture=new picture();
$suolue=$picture->ResizeImage($file);
$path_translated = "upload/";//上传文件夹
$UpLoadPath = addslashes(dirname($path_translated))."/upload/";
$FileName = $UpLoadPath."$upfile_name";//$upfile_name就是上传的文件名
if($path_translated==0)
{
mkdir("upload");
}
$picAlt = $_POST['picAlt'];
$image_type = array('jpg', 'gif', 'bmp', 'jpeg', 'pcx', 'tiff', 'png', 'svg');
if (($pos = strrpos($_FILES['photofile']['name'], '.')) !== false) {
$file_ext = strtolower(substr($_FILES['photofile']['name'], $pos + 1));
}
if (!in_array($file_ext, $image_type))
{
echo "<script>alert('只能上传图片格式的文件');</script>";
exit();
}
//函数 move_uploaded_file(,); 带两个参数 前面一个是临时文件名,后面是移动过后的真实文件名
$up = move_uploaded_file($file_name,"upload/$file");
if($up==1)
{
$file_url=$FileName.$file;
echo "<meta http-equiv='content-type' content='text/html; charset=".WIKI_CHARSET."'>";
//echo '<input id = "msg" type="hidden" value ="'.$suolue.'">';
//echo '<script type="text/javascript">alert(document.getElementById("msg").value);</script>';
echo '<script type="text/javascript">parent.ThcInsertPicOrder("'.$file_url.'");</script>';
exit();
}
else
{
echo "<script>alert('上传失败!');</script>";
exit();
}
}
?>
<?php
header("Content-type:image/jpeg");
?>
<?php
class picture{
function ResizeImage($filename){
list($width, $height) = getimagesize($filename);
$new_width =300;
$new_height =300;
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0,0,0,0,$new_width, $new_height,$width,$height);
imagejpeg($image_p);
return $image;
//return imagejpeg($image_p);
}
}
?> 这是缩略图的功能单独运行可以实现,但是下面的代码调用上面的方法就得不到宽和高的值 $image值也没空 请教一下各位高手啊!!!万分感谢!!!
<?php
include_once('sleditor.php');
$upok=1;
if($upok){
$file=($_FILES['photofile']['name']);
$file_name = ($_FILES['photofile']['tmp_name']);
$picture=new picture();
$suolue=$picture->ResizeImage($file);
$path_translated = "upload/";//上传文件夹
$UpLoadPath = addslashes(dirname($path_translated))."/upload/";
$FileName = $UpLoadPath."$upfile_name";//$upfile_name就是上传的文件名
if($path_translated==0)
{
mkdir("upload");
}
$picAlt = $_POST['picAlt'];
$image_type = array('jpg', 'gif', 'bmp', 'jpeg', 'pcx', 'tiff', 'png', 'svg');
if (($pos = strrpos($_FILES['photofile']['name'], '.')) !== false) {
$file_ext = strtolower(substr($_FILES['photofile']['name'], $pos + 1));
}
if (!in_array($file_ext, $image_type))
{
echo "<script>alert('只能上传图片格式的文件');</script>";
exit();
}
//函数 move_uploaded_file(,); 带两个参数 前面一个是临时文件名,后面是移动过后的真实文件名
$up = move_uploaded_file($file_name,"upload/$file");
if($up==1)
{
$file_url=$FileName.$file;
echo "<meta http-equiv='content-type' content='text/html; charset=".WIKI_CHARSET."'>";
//echo '<input id = "msg" type="hidden" value ="'.$suolue.'">';
//echo '<script type="text/javascript">alert(document.getElementById("msg").value);</script>';
echo '<script type="text/javascript">parent.ThcInsertPicOrder("'.$file_url.'");</script>';
exit();
}
else
{
echo "<script>alert('上传失败!');</script>";
exit();
}
}
?>
$picture=new picture();
$suolue=$picture->ResizeImage($file_name);
$file_name = ($_FILES['photofile']['tmp_name']);
$picture=new picture();
$suolue=$picture->ResizeImage($file_name);
$filename不是临时路径吗?
$up输出下看看是上面,还有,你都没有返回文件保存路径,那么ResizeImage($filename)还能获取的到图片大小么???
输出是1
如果是 $suolue=$picture->ResizeImage($filename);
输不出来值;我是用js弹框方式做的
1、需要你提交过来,那么获取到了tmp_name(文件的物理路径)
2、进行上传
3、上传完毕,你那个函数要进行路径的返回(如果$up == 1),然后再根据返回的路径获取图片的大小