上传默认图片,如果用户没有上传任何 [英] Upload default image if user didn't upload any

查看:148
本文介绍了上传默认图片,如果用户没有上传任何的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段代码upload.php

I have a piece of code from upload.php

$uploaddir = '../photo/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
if(move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
{
    //...
}

如何添加一个函数,如果用户没有上传图片,那么默认图片上传?

How can I add a function that if user didn't upload an image, then a default image is uploaded?

推荐答案

你也可以使用这个:
(当然在echo下面) b

you can use this also: (of course under echo "" in case of php)

// Replace source with other image in case user didn't upload any photo
$('img').error(function(){
        $(this).attr('src', 'missing.png');
});

// Or, hide the 'broken image' 
$("img").error(function(){
        $(this).hide();
});

这篇关于上传默认图片,如果用户没有上传任何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆