有人能看到我做得不对吗?没有上传任何图像?
我正在尝试使用simpleImage类调整图像大小
这是我的代码
if($_FILES['file']['name']!='')
{
$tmp_name = $_FILES["file"]["tmp_name"];
$cname = str_replace(' ', '-', $candidate_name);
$file_name = preg_replace("/[^a-zA-Z0-9.]/", "", $cname);
$fileUpload = move_uploaded_file($tmp_name,"uploads/images/".$image_name);
$image = new SimpleImage();
$image->load($fileUpload);
$image->resize(150,180);
$resize_rename = $fileUpload.$file_name;
$image->save($resize_rename);
unlink($fileUpload); //delete the original file
$img = ''.$resize_rename.'';
}else{
$img = '';
}
图像没有被上传到uploads/images/,而是一个没有扩展名的文件被上传到根目录。
如果不能测试,可能会有错误,但我认为,您应该使用已移动的文件的路径作为SimpleImage
类的输入(但从未查看过该类(
$img=false;
if( isset( $candidate_name ) && !empty( $_FILES['file'] ) ){
$obj=(object)$_FILES['file'];
$tmp=$obj->tmp_name;
$name=$obj->name;
$cname = str_replace( ' ', '-', $candidate_name );
$fname = preg_replace( '/[^a-zA-Z0-9.]/', '', $cname );
$target = __DIR__ . '/uploads/images/' . $name;
$status = move_uploaded_file( $tmp, $target );
if( $status ){
$newname = __DIR__. '/uploads/images/' . $fname;
$image = new SimpleImage();
$image->load( $target );
$image->resize( 150, 180 );
$image->save( $newname );
@unlink( $target );
$img=$newname;
}
}