Russelauto
asked on
How to create a unique image file for each unique user and display the image via html.
I am trying to write a couple of lines in php that I'm going to insert into the "activate" function of a registration.php. The goal is that upon account activation a predefined image will be written into a predefined directory. The image name must be unipqe for each user. I was thinking along the lines of this:
$im = blanktemplate.png
$filename = "images/users/$user_id"
imagejpeg($im, $filename, 100);
Is this a good method? Am I thinking along the right lines here?
Then I want to display that image in an html page. Something like <img src={"$user_id".jpg}/> I want the image that's being displayed to be determined by the user that's logged in at the time.
$im = blanktemplate.png
$filename = "images/users/$user_id"
imagejpeg($im, $filename, 100);
Is this a good method? Am I thinking along the right lines here?
Then I want to display that image in an html page. Something like <img src={"$user_id".jpg}/> I want the image that's being displayed to be determined by the user that's logged in at the time.
ASKER
Would the md5 hash prevent them from linking to the image outside of the site?
Ok, I can create an image with the following:
$user_id = 1234; //instanciated for testing
$im = imagecreatefromjpeg("image s/blank.jp g");
$filename = "images/users/$user_id.jpg ";
imagejpeg($im, $filename, 100);
But I can't seem to view the file using a variable.
<img src=images/users/{$user_id .}jpg/> Does not work. Maybe I'm not instanciating the variable correctly. I'm trying it like this: <user_id="1234">
Ok, I can create an image with the following:
$user_id = 1234; //instanciated for testing
$im = imagecreatefromjpeg("image
$filename = "images/users/$user_id.jpg
imagejpeg($im, $filename, 100);
But I can't seem to view the file using a variable.
<img src=images/users/{$user_id
ASKER
<img src="images/users/{$user_i d.}jpg"/> Sorry, left out the quotations.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok I think you're code is good. I just need to somehow instanciate the variable user_id. I'm going to create a new question.
You could also do it like
$filename = "images/users/".md5($user_
and then
<img src={md5($user_id."xx1.jpg
which you would do when you don' want a user to be able to see other users images (just by changing the number.
The xx1 could be any string that you want (just keep them both the same).