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 PHP Upload Script

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 11-20-2005, 12:16 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
 



PHP Upload Script


Hi i need a php upload script please, i need it simply explaind so i can understand it thanks need it in php quick
NetworkTown.Net is offline  
Old 11-20-2005, 12:23 PM   #2 (permalink)
New Member
Join Date: Nov 2005
Posts: 4
Exoload is an unknown quantity at this point
 



Heres one i found off google:

<?php
//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv vvvvvvvvvv
// You may change maxsize, and allowable upload file types.
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^
//Mmaximum file size. You may increase or decrease.
$MAX_SIZE = 200000000000;

//Allowable file Mime Types. Add more mime types if you want
$FILE_MIMES = array('application/pdf','video/mpg','video/avi','image/jpeg','image/jpg','image/gif'
,'image/png','application/msword');

//Allowable file ext. names. you may add more extension names.
$FILE_EXTS = array('.pdf','.txt','.zip','.jpg','.png','.gif','. avi','.mpg','.mpeg','.asf');

//Allow file delete? no, if only allow upload only
$DELETABLE = false;

//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv vvvvvvvvvv
// Do not touch the below if you are not confident.
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^
/************************************************** **********
* Setup variables
************************************************** **********/
$site_name = $_SERVER['HTTP_HOST'];
$url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['php_SELF']);
$url_this = "http://".$_SERVER['HTTP_HOST'].$_SERVER['php_SELF'];

$upload_dir = "files/";
$upload_url = $url_dir."/files/";
$message ="";

/************************************************** **********
* Create upload Directory
************************************************** **********/
if (!is_dir("files")) {
if (!mkdir($upload_dir))
die ("upload_files directory doesn't exist and creation failed");
if (!chmod($upload_dir,0755))
die ("change permission to 755 failed.");
}

/************************************************** **********
* Process User's Request
************************************************** **********/
????: NamePros.com http://www.namepros.com/programming/141530-php-upload-script.html
if ($_REQUEST[del] && $DELETABLE) {
$resource = fopen("log.txt","a");
fwrite($resource,date("Ymd h:i:s")."DELETE - $_SERVER[REMOTE_ADDR]"."$_REQUEST[del]\n");
fclose($resource);

if (strpos($_REQUEST[del],"/.")>0); //possible hacking
else if (strpos($_REQUEST[del],$upload_dir) === false); //possible hacking
else if (substr($_REQUEST[del],0,6)==$upload_dir) {
unlink($_REQUEST[del]);
????: NamePros.com http://www.namepros.com/showthread.php?t=141530
print "<script>window.location.href='$url_this?message=d eleted successfully'</script>";
}
}
else if ($_FILES['userfile']) {
$resource = fopen("log.txt","a");
fwrite($resource,date("Ymd h:i:s")."upload - $_SERVER[REMOTE_ADDR]"
.$_FILES['userfile']['name']." "
.$_FILES['userfile']['type']."\n");
fclose($resource);

$file_type = $_FILES['userfile']['type'];
$file_name = $_FILES['userfile']['name'];
$file_ext = strtolower(substr($file_name,strrpos($file_name,". ")));

//File Size Check
if ( $_FILES['userfile']['size'] > $MAX_SIZE)
$message = "The file size is over 2MB.";
//File Type/Extension Check
else if (!in_array($file_type, $FILE_MIMES)
&&!in_array($file_ext, $FILE_EXTS) )
$message = "Sorry, $file_name($file_type) is not allowed to be uploaded.";
else
$message = do_upload($upload_dir, $upload_url);

print "<script>window.location.href='$url_this?message=$ message'</script>";
}
else if (!$_FILES['userfile']);
else
$message = "Invalid File Specified.";

/************************************************** **********
* List Files
************************************************** **********/
$handle=opendir($upload_dir);
$filelist = "";
while ($file = readdir($handle)) {
if(!is_dir($file) &&!is_link($file)) {
$filelist .= "<a href='$upload_dir$file'>".$file."</a>";
if ($DELETABLE) {
$delfile = $file;
$delfile = str_replace("%","%25",$delfile);
$delfile = str_replace("&","%26",$delfile);
$delfile = str_replace("+","%2b",$delfile);
$delfile = str_replace("?","%3f",$delfile);
$filelist .= " <a href='?del=$upload_dir".$delfile."' title='delete'>x</a>";
}
$filelist .= "<sub><small><small><font color=grey> ".date("d-m H:i", filemtime($upload_dir.$file))
."</font></small></small></sub>";
$filelist .="<br>";
}
}

function do_upload($upload_dir, $upload_url) {

$temp_name = $_FILES['userfile']['tmp_name'];
$file_name = $_FILES['userfile']['name'];
$file_name = str_replace("\\","",$file_name);
$file_name = str_replace("'","",$file_name);
$file_path = $upload_dir.$file_name;

//File Name Check
if ( $file_name =="") {
$message = "Invalid File Name Specified";
return $message;
}

$result = move_uploaded_file($temp_name, $file_path);
if (!chmod($file_path,0777))
$message = "change permission to 777 failed.";
else
$message = ($result)?"$file_name uploaded successfully." :
"Somthing is wrong with uploading a file.";
return $message;
}

?>

<center>
<font color=red><?=$_REQUEST[message]?></font>
<br>
<form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post">
upload File <input type="file" id="userfile" name="userfile">
<input type="submit" name="upload" value="upload">
</form>

<br><b>upload area</b>
<hr width=70%>
<?=$filelist?>
<hr width=70%>
<small><sup>Maintained by "Me"
<a style="text-decoration:none" href="http://URL-HERE/forum">Back</a>
</sup></small>
</center>
Exoload is offline  
Old 11-20-2005, 01:00 PM 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
 



can you put that in a php file
NetworkTown.Net is offline  
Old 11-20-2005, 01:17 PM   #4 (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
Here is something simple:

PHP Code:
<html>
<head>
<title>Image upload</title>
</head>

<body>

<form action="upload.php" method="post" enctype="multipart/form-data">
Image: <input type="file" name="image" size="20">&nbsp;
<input type="submit" name="submit" value="Upload">
</form>

<?php

//The directory to upload the images - Must be writable CHMOD 777
$upload_dir "images/";
//100kb - What size do you want to allow to be uploaded
$max_size 100000;

????: NamePros.com http://www.namepros.com/showthread.php?t=141530
if(
is_uploaded_file($_FILES['image']['tmp_name']))
{
  
$size $_FILES['image']['size'];

  if(
$size $max_size)
  {
    echo 
"File Too Large. File must be no larger than <b>$max_size</b> bytes.";
????: NamePros.com http://www.namepros.com/showthread.php?t=141530
    exit();
  }
  
$filename $_FILES['image']['name'];

  if(
file_exists($upload_dir.$filename))
  {
    echo 
"Error: The file named <b>$filename</b> already exists.";
    exit();
  }

  if(
move_uploaded_file($_FILES['image']['tmp_name'], $upload_dir.$filename))
  {
    echo 
"Your image uploaded successfully! Can be found here: <a href='/".$upload_dir.$filename."'>".$upload_dir.$filename."</a>";
    exit();
  }
  else
  {
    echo 
"There was a problem uploading your file. Please try again.";
    exit();
  }
}
?>
Eric is offline  
Old 11-21-2005, 01:47 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
 



dose not work

Originally Posted by SecondVersion
Here is something simple:

PHP Code:
<html>
<head>
<title>Image upload</title>
</head>

<body>

<form action="upload.php" method="post" enctype="multipart/form-data">
Image: <input type="file" name="image" size="20">&nbsp;
<input type="submit" name="submit" value="Upload">
</form>

<?php

//The directory to upload the images - Must be writable CHMOD 777
$upload_dir "images/";
//100kb - What size do you want to allow to be uploaded
$max_size 100000;

if(
is_uploaded_file($_FILES['image']['tmp_name']))
{
  
$size $_FILES['image']['size'];

  if(
$size $max_size)
  {
    echo 
"File Too Large. File must be no larger than <b>$max_size</b> bytes.";
    exit();
  }
  
$filename $_FILES['image']['name'];

  if(
file_exists($upload_dir.$filename))
  {
    echo 
"Error: The file named <b>$filename</b> already exists.";
????: NamePros.com http://www.namepros.com/showthread.php?t=141530
    exit();
  }

  if(
move_uploaded_file($_FILES['image']['tmp_name'], $upload_dir.$filename))
  {
    echo 
"Your image uploaded successfully! Can be found here: <a href='/".$upload_dir.$filename."'>".$upload_dir.$filename."</a>";
    exit();
  }
  else
  {
    echo 
"There was a problem uploading your file. Please try again.";
????: NamePros.com http://www.namepros.com/showthread.php?t=141530
    exit();
  }
}
?>
NetworkTown.Net is offline  
Old 11-21-2005, 04:00 PM   #6 (permalink)
Eating Pie
 
iNod's Avatar
Join Date: Nov 2004
Location: Canada
Posts: 2,272
iNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud of
 


Special Olympics AIDS/HIV Cystic Fibrosis Save The Children Baby Health Cystic Fibrosis
Try this..


PHP Code:
<?php
if($_POST[finshed] == '1') {
//The directory to upload the images - Must be writable CHMOD 777
$upload_dir "images/";
//100kb - What size do you want to allow to be uploaded
$max_size 100000;

if(
is_uploaded_file($_FILES['image']['tmp_name']))
{
  
$size $_FILES['image']['size'];

  if(
$size $max_size)
????: NamePros.com http://www.namepros.com/showthread.php?t=141530
  {
    echo 
"File Too Large. File must be no larger than <b>$max_size</b> bytes.";
    exit();
  }
  
$filename $_FILES['image']['name'];

  if(
file_exists($upload_dir.$filename))
????: NamePros.com http://www.namepros.com/showthread.php?t=141530
  {
    echo 
"Error: The file named <b>$filename</b> already exists.";
    exit();
  }

  if(
move_uploaded_file($_FILES['image']['tmp_name'], $upload_dir.$filename))
  {
    echo 
"Your image uploaded successfully! Can be found here: <a href='/".$upload_dir.$filename."'>".$upload_dir.$filename."</a>";
    exit();
  }
  else
  {
    echo 
"There was a problem uploading your file. Please try again.";
    exit();
  }
}
}else{
?>
<html>
<head>
<title>Image upload</title>
</head>

<body>

<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="finshed" value="1">
Image: <input type="file" name="image" size="20">&nbsp;
<input type="submit" name="submit" value="Upload">
</form>
</body>
</html> 
<?php ?>

iNod.
__________________
I feel old.
iNod is offline  
Old 11-22-2005, 03:06 AM   #7 (permalink)
AJ
NamePros Regular
Join Date: Jun 2005
Location: Indiana, USA
Posts: 391
AJ is a jewel in the roughAJ is a jewel in the roughAJ is a jewel in the rough
 



Originally Posted by iNod
Try this..


PHP Code:
<?php
if($_POST[finshed] == '1') {
//The directory to upload the images - Must be writable CHMOD 777
$upload_dir "images/";
//100kb - What size do you want to allow to be uploaded
$max_size 100000;

if(
is_uploaded_file($_FILES['image']['tmp_name']))
{
  
$size $_FILES['image']['size'];
????: NamePros.com http://www.namepros.com/showthread.php?t=141530

  if(
$size $max_size)
  {
    echo 
"File Too Large. File must be no larger than <b>$max_size</b> bytes.";
    exit();
  }
  
$filename $_FILES['image']['name'];

  if(
file_exists($upload_dir.$filename))
  {
    echo 
"Error: The file named <b>$filename</b> already exists.";
????: NamePros.com http://www.namepros.com/showthread.php?t=141530
    exit();
  }

  if(
move_uploaded_file($_FILES['image']['tmp_name'], $upload_dir.$filename))
  {
    echo 
"Your image uploaded successfully! Can be found here: <a href='/".$upload_dir.$filename."'>".$upload_dir.$filename."</a>";
    exit();
  }
  else
  {
    echo 
"There was a problem uploading your file. Please try again.";
    exit();
  }
}
}else{
?>
<html>
<head>
<title>Image upload</title>
</head>

<body>

<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="finshed" value="1">
Image: <input type="file" name="image" size="20">&nbsp;
<input type="submit" name="submit" value="Upload">
</form>
</body>
</html> 
<?php ?>

iNod.
Seems to work great! And for once I found one that actually does work for me! Now maybe I can actually develop image-host.be lol!

BTW, Inod, is there anyway to get the image to pop up in a new window when you click on the link? I tried adding "target="_blank"" to it but it gave me some error.

EDIT: Never mind, I got it!
Last edited by AJ; 11-22-2005 at 03:41 AM.
AJ is offline  
Old 11-22-2005, 05:22 AM   #8 (permalink)
Joe
Senior Member
Join Date: Oct 2005
Location: Kent ~ U.K.
Posts: 3,209
Joe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud of
 


Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
wow, its a nice script! iNod continues to impress us all!... again!
__________________
Myself and "JackHeskett" are no longer associated with FusedHosting.net. Please pipe all PMs to admin [at] fusedhosting.net.
Joe is offline  
Old 11-22-2005, 01:24 PM   #9 (permalink)
Eating Pie
 
iNod's Avatar
Join Date: Nov 2004
Location: Canada
Posts: 2,272
iNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud of
 


Special Olympics AIDS/HIV Cystic Fibrosis Save The Children Baby Health Cystic Fibrosis
Originally Posted by josephheskett
wow, its a nice script! iNod continues to impress us all!... again!

Why Thank You!

But I just edited SecondVersions Script
__________________
I feel old.
iNod is offline  
Old 11-23-2005, 06:39 AM   #10 (permalink)
NamePros Member
 
Wybe's Avatar
Join Date: Nov 2005
Location: the Netherlands
Posts: 127
Wybe is on a distinguished road
 



I wrote a very detailed tutorial on this once. It's at:
http://minnwyb.beigetower.org/posts/web-upload-script/
__________________
accepts paypal and cookies
Wybe is offline  
Old 11-23-2005, 07:56 PM   #11 (permalink)
NamePros Member
Join Date: Oct 2005
Posts: 173
brianmn is on a distinguished road
 



Is there any way to get around the php setting that doesn't allow uploads over a certain size to be done... or the max execution time?

I would like to be able to have files uploaded that are up to 5MB and I have encountered the above problems.
brianmn is offline  
Old 11-23-2005, 08:23 PM   #12 (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
You could always...

PHP Code:
<?php

//30 seconds is the default in php.ini
????: NamePros.com http://www.namepros.com/showthread.php?t=141530
ini_set('max_execution_time''30'); 
//2M (megabytes) is the default in php.ini
ini_set('upload_max_filesize''2M';

?>
More settings:
http://us2.php.net/manual/en/ini.php#ini.list

More info on ini_set:
http://us2.php.net/ini_set
Eric is offline  
Old 11-24-2005, 12:51 AM   #13 (permalink)
NamePros Member
 
Wybe's Avatar
Join Date: Nov 2005
Location: the Netherlands
Posts: 127
Wybe is on a distinguished road
 



mind the last bracket in the second ini_set() tho for a sec. Good solution SecondVersion!
__________________
accepts paypal and cookies
Wybe is offline  
Old 11-24-2005, 09:40 AM   #14 (permalink)
NamePros Member
Join Date: Oct 2005
Posts: 173
brianmn is on a distinguished road
 



Wow, thanks a ton. That helped a lot.

So then it appears as though the values are only for the script that is doing the uploading at the time? So that i don't have to set it back to what it was once the script is done executing?
brianmn is offline  
Old 11-24-2005, 09:44 AM   #15 (permalink)
Eating Pie
 
iNod's Avatar
Join Date: Nov 2004
Location: Canada
Posts: 2,272
iNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud of
 


Special Olympics AIDS/HIV Cystic Fibrosis Save The Children Baby Health Cystic Fibrosis
int_set function sets a variable for Apache for just this excution. It will revert back to the normal settings in php.ini after processing. If you have safe_mode on for php than it may cause some problems or errors. if you experience this ask your host to change save_mode to off.

iNod.
__________________
I feel old.
iNod is offline  
Old 11-24-2005, 01:02 PM THREAD STARTER               #16 (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
 



Thank you all so much
NetworkTown.Net is offline  
Old 11-26-2005, 10:46 AM THREAD STARTER               #17 (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
 



Originally Posted by iNod
Try this..


PHP Code:
<?php
if($_POST[finshed] == '1') {
//The directory to upload the images - Must be writable CHMOD 777
????: NamePros.com http://www.namepros.com/showthread.php?t=141530
$upload_dir "images/";
//100kb - What size do you want to allow to be uploaded
$max_size 100000;

if(
is_uploaded_file($_FILES['image']['tmp_name']))
{
  
$size $_FILES['image']['size'];

  if(
$size $max_size)
  {
    echo 
"File Too Large. File must be no larger than <b>$max_size</b> bytes.";
    exit();
  }
  
$filename $_FILES['image']['name'];

  if(
file_exists($upload_dir.$filename))
  {
    echo 
"Error: The file named <b>$filename</b> already exists.";
    exit();
  }

  if(
move_uploaded_file($_FILES['image']['tmp_name'], $upload_dir.$filename))
  {
    echo 
"Your image uploaded successfully! Can be found here: <a href='/".$upload_dir.$filename."'>".$upload_dir.$filename."</a>";
    exit();
  }
  else
  {
    echo 
"There was a problem uploading your file. Please try again.";
    exit();
  }
}
}else{
?>
<html>
<head>
<title>Image upload</title>
</head>

<body>

<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="finshed" value="1">
Image: <input type="file" name="image" size="20">&nbsp;
<input type="submit" name="submit" value="Upload">
</form>
</body>
</html> 
<?php ?>

????: NamePros.com http://www.namepros.com/showthread.php?t=141530
iNod.
CAN YOU CHANGE THAT TO FILE UPLOAD INSTED OF IMAGE UPLOAD PLEASE THANKS
NetworkTown.Net is offline  
Old 11-26-2005, 05:43 PM   #18 (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
Originally Posted by ewirehosting
CAN YOU CHANGE THAT TO FILE UPLOAD INSTED OF IMAGE UPLOAD PLEASE THANKS
Nothing needs to be changed really. Aside from the folder you want them uploaded to...
????: NamePros.com http://www.namepros.com/showthread.php?t=141530

Anyway, you could do something like this:

PHP Code:
<?php

if($_POST['finshed'] == '1')
{
  
//The directory to upload the images - Must be writable CHMOD 777
  
$upload_dir "files/";
  
//100kb - What size do you want to allow to be uploaded
  
$max_size 100000;
  
//Limit file types?
  
$limit "yes";
  
//File types
????: NamePros.com http://www.namepros.com/showthread.php?t=141530
  
$allowed = array("txt""zip""rar"); //Etc

  
if(is_uploaded_file($_FILES['file']['tmp_name']))
  {
    
$size $_FILES['file']['size'];
    if(
$size $max_size)
    {
      echo 
"File Too Large. File must be no larger than <b>$max_size</b> bytes.";
      exit();
    }
    
    
$filename $_FILES['file']['name'];
    
$ext explode("."$filename);
    
$ext_check trim($ext[1]);
    
    if(
$limit == "yes" && !in_array($ext_check$allowed))
    {
      echo 
"File type not allowed.";
      exit();
    }
    if(
file_exists($upload_dir.$filename))
    {
      echo 
"Error: The file named <b>$filename</b> already exists.";
      exit();
    }
    if(
move_uploaded_file($_FILES['file']['tmp_name'], $upload_dir.$filename))
    {
      echo 
"Your image uploaded successfully! Can be found here: <a href='/".$upload_dir.$filename."'>".$upload_dir.$filename."</a>";
      exit();
    }
    else
    {
      echo 
"There was a problem uploading your file. Please try again.";
      exit();
    }
  }
}
else
{
?>
<html>
<head>
<title>File upload</title>
</head>

<body>

<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="finshed" value="1">
Image: <input type="file" name="file" size="20">&nbsp;
<input type="submit" name="submit" value="Upload">
</form>
</body>
</html>
<?php
}
?>
Eric is offline  
Old 11-27-2005, 12:04 PM   #19 (permalink)
NamePros Member
Join Date: Aug 2005
Posts: 145
JustinWI is on a distinguished road
 



Great code. One question for you. How can I limit what files can be chosen throught the dialog box when choosing a file (ie. 'mpg', 'mp3'). I know it currently will show an error after trying to upload an extension that isn't allowed, but how do I limit the dialog box.

Thanks
JustinWI is offline  
Old 11-27-2005, 10:51 PM   #20 (permalink)
Eating Pie
 
iNod's Avatar
Join Date: Nov 2004
Location: Canada
Posts: 2,272
iNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud of
 


Special Olympics AIDS/HIV Cystic Fibrosis Save The Children Baby Health Cystic Fibrosis
Originally Posted by JustinWI
Great code. One question for you. How can I limit what files can be chosen throught the dialog box when choosing a file (ie. 'mpg', 'mp3'). I know it currently will show an error after trying to upload an extension that isn't allowed, but how do I limit the dialog box.

Thanks

????: NamePros.com http://www.namepros.com/showthread.php?t=141530
PHP doesn't have a way to do this sorry.

iNod
__________________
I feel old.
iNod is offline  
Old 12-04-2005, 03:46 AM   #21 (permalink)
Joe
Senior Member
Join Date: Oct 2005
Location: Kent ~ U.K.
Posts: 3,209
Joe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud of
 


Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
i have another question that i hope you can help with...
does php have a script that will record the ip address and file name when an image is uploaded? in a seperate file
e.g.
text.jpg ¦ 111.111.111.111

i hope it can be done
__________________
Myself and "JackHeskett" are no longer associated with FusedHosting.net. Please pipe all PMs to admin [at] fusedhosting.net.
Joe is offline  
Old 12-04-2005, 04:04 AM   #22 (permalink)
NamePros Regular
Join Date: May 2005
Location: Oklahoma City Oklahoma
Posts: 467
shanee86 is on a distinguished road
 



I think so I own a image hosting site and it inputs the ip with the picture they upload. But I didn't make it lol so have no idea. Also I have one question to ohm how can you make a thumb from a image they user uploads and make it clickable to a full page with the full size image on it I really want to do this for my image host site but have no idea? Thanks.
shanee86 is offline  
Old 12-04-2005, 04:49 AM   #23 (permalink)
NamePros Member
 
bquast's Avatar
Join Date: Nov 2005
Location: Hardisty, Alberta Canada
Posts: 179
bquast will become famous soon enough
 



Yeah, there is mysql ways to log ips and flat file ways to log the ip address, always depends on what you want to do.
bquast is offline  
Old 12-04-2005, 06:30 AM   #24 (permalink)
Joe
Senior Member
Join Date: Oct 2005
Location: Kent ~ U.K.
Posts: 3,209
Joe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud of
 


Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
well can anyone tell me? coz this would be really good if i could record the ip?

perhaps shanee86, would you mind sending me your php upload script? and i could have a look through it? i may not be able to make a php script, but i can understand and edit it

Thanks - Joe
__________________
Myself and "JackHeskett" are no longer associated with FusedHosting.net. Please pipe all PMs to admin [at] fusedhosting.net.
Joe is offline  
Old 12-08-2005, 09:45 AM   #25 (permalink)
NamePros Member
Join Date: Dec 2005
Posts: 34
Webviper2006 is an unknown quantity at this point
 



You sould know google is a bad search engine. The best ones are Ask Jeeves or Yahoo! The other ones like AOL, or any other one are really bad. So the best just ASK JEEVES.
Webviper2006 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
Googlism - What does google think of you? deadserious The Break Room 55 12-15-2005 10:09 AM
Huge Script Pack for $5 with Resale Rights dsforsaken Scripts For Sale 32 12-03-2005 09:46 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 01:08 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