Jump to content


Photo

random names for images


  • Please log in to reply
7 replies to this topic

#1 chriscloyd

chriscloyd
  • Members
  • PipPipPip
  • Advanced Member
  • 489 posts
  • LocationArizona

Posted 12 April 2006 - 01:24 PM

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?

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

44 bugs in my java code
44 bugs in my java code
Fix 1 bug, and complie again
122 bugs in my java code

#2 LIJI

LIJI
  • New Members
  • Pip
  • Newbie
  • 6 posts
  • LocationIsrael

Posted 12 April 2006 - 01:50 PM

[!--quoteo(post=364018:date=Apr 12 2006, 03:24 PM:name=chriscloyd)--][div class=\'quotetop\']QUOTE(chriscloyd @ Apr 12 2006, 03:24 PM) View Post[/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?

<?
//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!";
} 
?>
[/quote]
idea:
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


#3 MoFish

MoFish
  • Members
  • PipPipPip
  • Advanced Member
  • 210 posts

Posted 12 April 2006 - 01:51 PM

did you get your upload working and thumbnail bit going aswell? im still having problems :(

#4 chriscloyd

chriscloyd
  • Members
  • PipPipPip
  • Advanced Member
  • 489 posts
  • LocationArizona

Posted 12 April 2006 - 02:39 PM

i got an upload working were it stores it into the database but im working on giving them random names and creating thumbnails
44 bugs in my java code
44 bugs in my java code
Fix 1 bug, and complie again
122 bugs in my java code

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 12 April 2006 - 02:48 PM

[!--quoteo(post=364046:date=Apr 12 2006, 02:39 PM:name=chriscloyd)--][div class=\'quotetop\']QUOTE(chriscloyd @ Apr 12 2006, 02:39 PM) View Post[/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]
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 chriscloyd

chriscloyd
  • Members
  • PipPipPip
  • Advanced Member
  • 489 posts
  • LocationArizona

Posted 12 April 2006 - 02:56 PM

Could someone please help me creat the thumbnails and giving them a random name?
44 bugs in my java code
44 bugs in my java code
Fix 1 bug, and complie again
122 bugs in my java code

#7 Yesideez

Yesideez
  • Members
  • PipPipPip
  • Advanced Member
  • 2,334 posts
  • LocationDevon, UK

Posted 12 April 2006 - 03:06 PM

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:
$randomname='img'.time().'.jpg';
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.
Not a pro just an enthusiast :)

if (empty($coffee)) {$coffee=new coffee();}

Please surround any code using the CODE tags - I rarely look at anything without them

#8 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 12 April 2006 - 03:12 PM

[!--quoteo(post=364055:date=Apr 12 2006, 03:06 PM:name=Yesideez)--][div class=\'quotetop\']QUOTE(Yesideez @ Apr 12 2006, 03:06 PM) View Post[/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:
$randomname='img'.time().'.jpg';
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]
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users