sark9012
sark9012

Reputation: 5747

Put an image into a directory

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 file and put it into a different directory when a user reigsters?

Upvotes: 0

Views: 224

Answers (2)

Alec
Alec

Reputation: 9078

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="" />'; } ?>

Upvotes: 2

gblazex
gblazex

Reputation: 50137

Use the copy function. It can't get any easier than that.

copy("img/default.jpg", $directory.$userid.".jpg");

Upvotes: 0

Related Questions