NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Need PHP Help.

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 07-04-2006, 10:49 PM THREAD STARTER               #1 (permalink)
Account Closed
 
hexthem4n's Avatar
Join Date: Jan 2005
Posts: 78
hexthem4n is on a distinguished road
 



Need PHP Help.


I need the following code to put a random number onto the file name. Like say you upload image.jpg, I want it to be like 213image.jpg after its uploaded. So that I dont have to worry about people getting the re-name your image error. Any help would be awsome! Here is the code.

PHP Code:
<?
//set these variables-----------------------------------------------------------------
$path "test/uploads/";   //path to your targetfolder after your domain
$max_size 1000000;          //maximum filesize

//optionally
$domain $_SERVER["HTTP_HOST"];      //your domainname - change if necessary like "www.wza.be"
????: NamePros.com http://www.namepros.com/programming/213593-need-php-help.html

//------------------------------------------------------------------------------------
?>

<?

if (!isset($HTTP_POST_FILES['userfile'])) exit;

if (
is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {

if (
$HTTP_POST_FILES['userfile']['size']>$max_size) {
        echo 
"<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">File is too big !</font><br>\n"; exit; }
if ((
$HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/png")) {
????: NamePros.com http://www.namepros.com/showthread.php?t=213593

        if (
file_exists("../".$path $HTTP_POST_FILES['userfile']['name'])) {
                echo 
"<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">There already exists a file with this name, please rename your file and try again</font><br>\n"; exit; }

        
$res copy($HTTP_POST_FILES['userfile']['tmp_name'], "../".$path .$HTTP_POST_FILES['userfile']['name']);

        if (!
$res) { echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">Didn't work, please try again</font><br>\n"; exit; } else {
        
?>
<br>
<p> <font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif"><strong>Find 
          your file here: </strong></font><font color="#333333" face="Geneva, Arial, Helvetica, sans-serif"><strong><font color="#990000"><a href="http://<? echo $domain?>/<? echo "../".$path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>" target="_blank"><br>
          </a></font></strong><font color="#990000"><a href="http://<? echo $domain?>/<? echo "../".$path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>" target="_blank"><font color="#B6B66D">http://<? echo $domain?>/<? echo $path?><? echo $HTTP_POST_FILES['userfile']['name']; ?></font></a><strong><a href="http://<? echo $domain?>/<? echo "../".$path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>" target="_blank"><br>
          </a></strong></font><br>
          <strong><font color="#FFFFFF">HTML:</font></strong><br>
          <font color="#B6B66D">&lt;img src=&quot;http://<? echo $domain?>/<? echo $path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>&quot;&gt;</font><br>
  <br>
          <font color="#FFFFFF"><strong>BBCode: </strong><strong></strong></font><font color="#990000"><strong><br>
          </strong> <font color="#B6B66D">[img]http://<? echo $domain?>/<? echo $path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>[/img]</font></font></font></p>
<?
 
}
echo 
"<font color=\"#B6B66D\" face=\"Geneva, Arial, Helvetica, sans-serif\"><hr>";
echo 
"Name: ".$HTTP_POST_FILES['userfile']['name']."<br>\n";
echo 
"Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>\n";
echo 
"Type: ".$HTTP_POST_FILES['userfile']['type']."<br>\n";
echo 
"</font>";
}

}

?>
hexthem4n is offline  
Old 07-05-2006, 05:08 AM   #2 (permalink)
NamePros Regular
 
Noobie's Avatar
Join Date: Feb 2006
Location: Montreal, Quebec, Canada
Posts: 324
Noobie is on a distinguished road
 



you can use uniqid()
__________________
Goldkey.com is a scam
What's your BMI? | Timestamp Generator
Noobie is offline  
Old 07-05-2006, 08:45 PM   #3 (permalink)
New Member
Join Date: Jul 2006
Posts: 13
bttfpromo is an unknown quantity at this point
 



Ahahaha....I have this done on my own website... You'll need to change variables and what's highlighted.



PHP Code:
        $micro=substr (md5 (microtime ()), 13);
????: NamePros.com http://www.namepros.com/showthread.php?t=213593
    
rename('[b]files/[/b]'.$uploaded_file_name'[b]files/[/b]'.$micro$uploaded_file_name);
    
$uploaded_file_name=$micro.$uploaded_file_name
bttfpromo is offline  
Old 07-07-2006, 01:47 AM   #4 (permalink)
NamePros Regular
 
-PS-'s Avatar
Join Date: Jun 2006
Location: Sydney
Posts: 251
-PS- will become famous soon enough-PS- will become famous soon enough
 



Originally Posted by bttfpromo
Ahahaha....I have this done on my own website... You'll need to change variables and what's highlighted.



PHP Code:
        $micro=substr (md5 (microtime ()), 13);
    
rename('[b]files/[/b]'.$uploaded_file_name'[b]files/[/b]'.$micro$uploaded_file_name);
????: NamePros.com http://www.namepros.com/showthread.php?t=213593
    
$uploaded_file_name=$micro.$uploaded_file_name

i would recomend changing $micro=substr(...) to something like $micro=rand(1,999) if you wish to keep the orginal file name in the "name". md5 makes hex numbers, meaning you can get the letters a-f in there as well FYI.
-PS- is offline  
Old 07-07-2006, 03:39 AM THREAD STARTER               #5 (permalink)
Account Closed
 
hexthem4n's Avatar
Join Date: Jan 2005
Posts: 78
hexthem4n is on a distinguished road
 



Ya but how can I make it show the correct link after it uploads?
hexthem4n is offline  
Old 07-07-2006, 10:09 AM   #6 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,796
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
What is the URL supposed to be when they upload?

Like http://site.com/image.php?image=_______ ??
Dan is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 09:19 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger