本文章是一款图片上传代码,他可以把上传到服务器的图片在进行预览修改,如果是你想的你就可以保存了,不是可以删除再重新上传,实例代码如下:
-
if(!isset($_session))session_start();
-
-
-
-
-
-
-
-
-
-
-
-
function upload($data){
-
if(!$data['file']){
-
echo '<script>alert("file不能为空!");</script>';exit;
-
}
-
if(!$data['img_tag_id']){
-
echo '<script>alert("预览图片标签id不能为空!");</script>';exit;
-
}
-
if(!$data['img_dir']){
-
echo '<script>alert("图片上传目录不能为空!");</script>';exit;
-
}
-
if(!isset($data['max_file_size'])){
-
$data['max_file_size'] = 1024 * 1024;
-
}else{
-
$data['max_file_size'] = $data['max_file_size'] * 1024 * 1024;
-
}
-
if(!isset($data['type_array'])){
-
$data['type_array'] = array('image/pjpeg', 'image/jpeg', 'image/gif');
-
}
-
if(!isset($data['sub_type'])){
-
$data['sub_type'] = 'upload';
-
}
-
-
$imgpath = '';
-
if(isset($data['sub_type']) && $data['sub_type'] == 'delete'){
-
if(isset($_session['name']) && $_session['name']){
-
if(is_file($_session['imgpath'])){
-
$b = unlink($_session['imgpath']);
-
}