开发者

Put an image into a directory

开发者 https://www.devze.com 2023-01-06 12:28 出处:网络
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.

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");
0

精彩评论

暂无评论...
验证码 换一张
取 消