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 img upload script 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 03-08-2006, 01:53 PM THREAD STARTER               #1 (permalink)
Account Closed
Join Date: Oct 2005
Location: United Kingdom
Posts: 1,554
NetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really nice
 



img upload script help


i got this code from a namepors member that was posted last year or some thing but just help me out any way how do i change the code so it makes random names for file name the code is:
PHP Code:
<?
//set these variables-----------------------------------------------------------------
$path "upload/";   //path to your targetfolder after your domain
$max_size 500000;          //maximum filesize

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

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>file upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#990000" link="#990000" vlink="#990000" alink="#990000" leftmargin="20" topmargin="20" marginwidth="20" marginheight="20">

<FORM ENCTYPE="multipart/form-data" ACTION="index.php" METHOD="POST">
        <strong><font color="#990000" face="Geneva, Arial, Helvetica, sans-serif">IMAGE (jpg/gif) </font></strong><font color="#990000">:</font>
        <INPUT TYPE="file" NAME="userfile">
        <INPUT TYPE="submit" VALUE="Upload">
</FORM>

<br>
<?

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")) {

        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="#333333" face="Geneva, Arial, Helvetica, sans-serif">Find your file here: <strong><font color="#990000"><a href="http://<? echo $domain?>/<? echo "../".$path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>" target="_blank"><br>
  http://<? echo $domain?>/<? echo $path?><? echo $HTTP_POST_FILES['userfile']['name']; ?><br>
  </a></font></strong><br>
<?
 
}
echo 
"<font color=\"#333333\" 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>";
echo 
"<br><br><img src=\"http://".$domain."/".$path.$HTTP_POST_FILES['userfile']['name']."\">";
} else { echo 
"<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">Verkeerd bestandstype, enkel gif, jpg of png !!!</font><br>\n"; exit; }

}

?>
????: NamePros.com http://www.namepros.com/showthread.php?t=174816


</body>
</html>
and like so the when it gives the url it is like imageshack page with the forum codes ect, and how do i make it so that there are dirrent pages like index.php and upload.php - view.php ect
NetworkTown.Net is offline  
Old 03-09-2006, 04:39 AM   #2 (permalink)
NamePros Member
Join Date: Nov 2005
Posts: 66
nigelwong is an unknown quantity at this point
 



just add additional echo lines, with what you want keeping the variables but changing whats around it.
nigelwong is offline  
Old 03-09-2006, 08:55 AM THREAD STARTER               #3 (permalink)
Account Closed
Join Date: Oct 2005
Location: United Kingdom
Posts: 1,554
NetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really nice
 



but thats what i want help on edit the code for me and show me
NetworkTown.Net is offline  
Old 03-09-2006, 09:56 PM   #4 (permalink)
 
BillyConnite's Avatar
Join Date: Jul 2005
Location: Coffs H, Australia
Posts: 3,456
BillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond repute
 


Wildlife Parkinson's Disease Parkinson's Disease
Well, the code is very outdated, and you might want to consider searching around for a newer one, but I fixed it up for you anyway.
PHP Code:
<?
//set these variables-----------------------------------------------------------------
$path "upload/";   //path to your targetfolder after your domain
$max_size 500000;          //maximum filesize

//optionally
$domain $_SERVER["HTTP_HOST"];      //your domainname - change if necessary like "www.wza.be"

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>file upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#990000" link="#990000" vlink="#990000" alink="#990000" leftmargin="20" topmargin="20" marginwidth="20" marginheight="20">

<FORM ENCTYPE="multipart/form-data" ACTION="index.php" METHOD="POST">
        <strong><font color="#990000" face="Geneva, Arial, Helvetica, sans-serif">IMAGE (jpg/gif) </font></strong><font color="#990000">:</font>
        <INPUT TYPE="file" NAME="userfile">
????: NamePros.com http://www.namepros.com/showthread.php?t=174816
        <INPUT TYPE="submit" VALUE="Upload">
</FORM>

<br>
<?

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")) {

        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; }
        
$ext=strtolower(ereg_replace("^.+\\.([^.]+)$""\\1",$HTTP_POST_FILES['userfile']['name']));
        
$imagename=substr(md5(uniqid(rand())),0,15).".".$ext;
????: NamePros.com http://www.namepros.com/showthread.php?t=174816
        
$res copy($HTTP_POST_FILES['userfile']['tmp_name'], "../".$path .$imagename.$ext);

        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="#333333" face="Geneva, Arial, Helvetica, sans-serif">Find your file here: <strong><font color="#990000"><a href="http://<? echo $domain?>/<? echo "../".$path?><? echo $imagename?>" target="_blank"><br>
  http://<? echo $domain?>/<? echo $path?><? echo $imagename?><br>
  </a></font></strong><br>
<?
}
echo 
"<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\"><hr>";
echo 
"Name: ".$imagename."<br>\n";
echo 
"Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>\n";
echo 
"Type: ".$HTTP_POST_FILES['userfile']['type']."<br>\n";
echo 
"</font>";
echo 
"<br><br><img src=\"http://".$domain."/".$path.$imagename."\">";
} else { echo 
"<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">Verkeerd bestandstype, enkel gif, jpg of png !!!</font><br>\n"; exit; }

}

?>


</body>
</html>
Replace that with yours, and you should be good to go
BillyConnite is online now  
Old 03-11-2006, 02:00 PM THREAD STARTER               #5 (permalink)
Account Closed
Join Date: Oct 2005
Location: United Kingdom
Posts: 1,554
NetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really nice
 



how do i make it so it randomize's the names?
NetworkTown.Net is offline  
Old 03-11-2006, 02:31 PM   #6 (permalink)
.PJ
NamePros Regular
 
.PJ's Avatar
Join Date: Aug 2004
Posts: 363
.PJ is on a distinguished road
 



It might be a better idea to search google for a script that does it instead of changing an older script to do it.

PJ
__________________
L33TSig.net
.PJ is offline  
Old 03-11-2006, 07:30 PM   #7 (permalink)
 
BillyConnite's Avatar
Join Date: Jul 2005
Location: Coffs H, Australia
Posts: 3,456
BillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond repute
 


Wildlife Parkinson's Disease Parkinson's Disease
Originally Posted by gameztown
how do i make it so it randomize's the names?
The script I posted above should be doing that for you...

Code:
$ext=strtolower(ereg_replace("^.+\\.([^.]+)$", "\\1",$HTTP_POST_FILES['userfile']['name']));
$imagename=substr(md5(uniqid(rand())),0,15).".".$ext;
The first line gets the extension of the image e.g. .jpg
The second line substr(md5(uniqid(rand())),0,15) creates a random number 15 characters in length and creates the 'imagename' variable, which is the random number with the extenstion added to it, giving you a new random file name e.g. 243543657245683.jpg
????: NamePros.com http://www.namepros.com/showthread.php?t=174816

Rhett.
BillyConnite is online now  
Old 03-26-2006, 02:45 PM THREAD STARTER               #8 (permalink)
Account Closed
Join Date: Oct 2005
Location: United Kingdom
Posts: 1,554
NetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really nice
 



Whats the best free or cheap img host script out?
NetworkTown.Net is offline  
Old 03-26-2006, 03:49 PM   #9 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Umm yeah, this an old and outdated script, but:
PHP Code:
<?php

//Path to the image/file folder
$path "upload/";

//Maximum filesize
$max_size 500000;

//True or false to limit file types
$limit_file_type true;

//If $limit_file_type is set to true, set the types here
$allowed_types = array("image/gif""image/jpeg""image/jpg""image/png");

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>File upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body
{
  background-color: #ffffff;
  color: #990000;
  margin-top: 20px;
  margin-left: 20px;
}
a, a:visited, a:hover
{
  color: #990000;
}
.error
{
  color: #FF0000;
}
-->
</style>
</head>

<body>

<form enctype="multipart/form-data" action="index.php" method="post">
<strong>Image: </strong>
<input type="file" name="userfile"><input type="submit" name="submit" value="Upload">
</form>
<br>
<?php

if(!isset($_FILES['userfile']))
{
  exit;
}
if(
is_uploaded_file($_FILES['userfile']['tmp_name']))
{
  if(
$_FILES['userfile']['size'] > $max_size)
  {
    echo 
'<span class="error">File is too big !</span><br>';
    exit;
  }
  
$filename $_FILES['userfile']['name'];
  
$get_ext explode("."$filename);
  
$ext trim($get_ext[1]);
  
$filename md5(uniqid(rand(010), true)).'.'.$ext;

  if(
$limit_file_types)
  {
    if(
in_array($_FILES['userfile']['type'], $allowed_types))
    {
      
$res move_uploaded_file($_FILES['userfile']['tmp_name'], $path.$filename);
????: NamePros.com http://www.namepros.com/showthread.php?t=174816
      if(!
$res)
      {
        echo 
'<span class="error">Didn\'t work, please try again.</span><br>';
        exit;
      }
      else
      {
      
?>
      <br>
      <p>Find your file here: <br>
      <strong><a href="http://mydomain.com/<?php echo $path.$filename?>" target="_blank"><?php echo $filename?></a>
      <br></strong><br>
      <?php
      
}
      echo 
'<hr>
????: NamePros.com http://www.namepros.com/showthread.php?t=174816
      Name (new name): '
.$filename.'<br>
      Size: '
.$_FILES['userfile']['size'].' bytes<br>
      Type: '
.$_FILES['userfile']['type'].'<br><br><br>
      <img src="http://mydomain.com/'
.$path.$filename.'">';
    }
    else
    {
      echo 
'<span class="error">Only jpg, jpeg, png, and gif are supported.</span>';
      exit;
    }
  }
  else
  {
    
$res move_uploaded_file($_FILES['userfile']['tmp_name'], $path.$filename);
    if(!
$res)
    {
      echo 
'<span class="error">Didn\'t work, please try again.</span><br>';
      exit;
    }
    else
    {
    
?>
    <br>
    <p>Find your file here: <br>
    <strong><a href="http://mydomain.com/<?php echo $path.$filename?>" target="_blank"><?php echo $filename?></a>
    <br></strong><br>
    <?php
    
}
    echo 
'<hr>
    Name (new name): '
.$filename.'<br>
    Size: '
.$_FILES['userfile']['size'].' bytes<br>
    Type: '
.$_FILES['userfile']['type'].'<br><br><br>
    <img src="http://mydomain.com/'
.$path.$filename.'">';
  }
}
?>

</body>
</html>
I cleaned it up a tad, will give it another look over later..see if that works for you.
Note: anywhere it says mydomain.com, you need to change to your domain name.
Last edited by SecondVersion; 03-26-2006 at 03:53 PM.
Eric is offline  
Closed Thread


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Great Scripts for Sale With Resale Rights! Zeeble Scripts For Sale 20 01-04-2006 02:39 AM
Huge Xmas script pack sale $5.00 KPR Scripts For Sale 1 12-08-2005 07:25 PM
60.000 Templates, scripts, fonts, banners etc. $9.95 atkims Web Development Wanted 19 11-16-2004 10:48 AM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 05:47 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