I have a website where the users can upload an image. However, before they upload one, on registering I want a standard image to be put in the directory. Almost a placeholder image.
How do I get about writing PHP that would take a copy of a fi开发者_运维知识库le and put it into a different directory when a user reigsters?
You can work with a single placeholder image, and use that in case there isn't an uploaded image from the user. Example:
<php
$user_image = 'path/to/file.jpg';
if (file_exists($user_image)) {
echo '<img src="'.$user_image.'" alt="" />';
} else {
echo '<img src="path/to/placeholder.jpg" alt="" />';
}
?>
Use the copy
function. It can't get any easier than that.
copy("img/default.jpg", $directory.$userid.".jpg");
精彩评论