Jump to content

Archived

This topic is now archived and is closed to further replies.

chriscloyd

random names for images

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]

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
did you get your upload working and thumbnail bit going aswell? im still having problems :(

Share this post


Link to post
Share on other sites
i got an upload working were it stores it into the database but im working on giving them random names and creating thumbnails

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
Could someone please help me creat the thumbnails and giving them a random name?

Share this post


Link to post
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.

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.