Jump to content

random names for images


chriscloyd

Recommended Posts

okay i need help it uploads the file and enters it into the directory heres the actual part that uploads it works fine but i want to give the image a random name using numberand letters can u help me?

[code]<?
//other code above not shown for personal reasons
$target_path = "userimages/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$filename = $_FILES['uploadedfile']['name'];
$fileaddress = "userimages/".$_FILES['uploadedfile']['name'];
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
    mysql_query("INSERT INTO `pictures` (`pid`, `uid`, `file`, `description`, `filename`) VALUES ('', '$userid', '$fileaddress', NULL, '$filename')")
or die(mysql_error());
} else{
    echo "There was an error uploading the file, please try again!";
}
?>[/code]
Link to comment
Share on other sites

[!--quoteo(post=364018:date=Apr 12 2006, 03:24 PM:name=chriscloyd)--][div class=\'quotetop\']QUOTE(chriscloyd @ Apr 12 2006, 03:24 PM) [snapback]364018[/snapback][/div][div class=\'quotemain\'][!--quotec--]
okay i need help it uploads the file and enters it into the directory heres the actual part that uploads it works fine but i want to give the image a random name using numberand letters can u help me?

[code]<?
//other code above not shown for personal reasons
$target_path = "userimages/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$filename = $_FILES['uploadedfile']['name'];
$fileaddress = "userimages/".$_FILES['uploadedfile']['name'];
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
    mysql_query("INSERT INTO `pictures` (`pid`, `uid`, `file`, `description`, `filename`) VALUES ('', '$userid', '$fileaddress', NULL, '$filename')")
or die(mysql_error());
} else{
    echo "There was an error uploading the file, please try again!";
}
?>[/code]
[/quote]
idea:
[code]substr(trim(md5("sitename".$numberofrows)), 0,8) //number of rows can be gotten using a mysql function, i'll post it's name if needed[/code]
Link to comment
Share on other sites

[!--quoteo(post=364046:date=Apr 12 2006, 02:39 PM:name=chriscloyd)--][div class=\'quotetop\']QUOTE(chriscloyd @ Apr 12 2006, 02:39 PM) [snapback]364046[/snapback][/div][div class=\'quotemain\'][!--quotec--]
i got an upload working were it stores it into the database but im working on giving them random names and creating thumbnails
[/quote]
Link to comment
Share on other sites

I'm not advanced well enough with images and PHP to be able to offer help there as I've learnt what I need to know but I can help with the random filenames:
[code]$randomname='img'.time().'.jpg';[/code]
That will start each filename off with "img" and end in ".jpg" although if you're not using JPEGs all the time you might want to change that for whatever the file extension of the image is.
Link to comment
Share on other sites

[!--quoteo(post=364055:date=Apr 12 2006, 03:06 PM:name=Yesideez)--][div class=\'quotetop\']QUOTE(Yesideez @ Apr 12 2006, 03:06 PM) [snapback]364055[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I'm not advanced well enough with images and PHP to be able to offer help there as I've learnt what I need to know but I can help with the random filenames:
[code]$randomname='img'.time().'.jpg';[/code]
That will start each filename off with "img" and end in ".jpg" although if you're not using JPEGs all the time you might want to change that for whatever the file extension of the image is.
[/quote]

got problams posting the code sorry.

[a href=\"http://www.programmershelp.co.uk/showcode.php?e=220\" target=\"_blank\"]http://www.programmershelp.co.uk/showcode.php?e=220[/a]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.