Jump to content


Photo

Simple File Upload script


  • Please log in to reply
1 reply to this topic

#1 OsiViper

OsiViper
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 22 September 2006 - 11:45 PM

Ok, i have looked all over the internet for something like this.

I just want a simple file upload script that people can upload pictures to a folder on the website and once the file upload is complete, it will display a link to the uploaded file -- i would also like to have a size limit on files if possible.

Does anyone know of a script that can do this? i have found alot of upload scripts, but they are all just overly complicated for what i need.

#2 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 23 September 2006 - 12:24 AM

dusted this one off for you. Hope it works  ;D

<?php
ini_set("memory_limit","128M"); //can be reduced (I think) to limit files. Default is probably 20M
if ($_FILES['userfile']['name']) {
	$newfilename=str_replace(" ","_",$_FILES['userfile']['name']); //files with spaces come in as underscores -- fix
	move_uploaded_file($_FILES['userfile']['tmp_name'], realpath(".")."/" . $newfilename);
//	chmod(realpath(".")."/".$_FILES['userfile']['name'],0777); //may be necessary -- depends
	echo "The file <a href=\"".$newfilename."\">".$newfilename."</a> was received.");
	echo "<br>\n<a href=\"".$filea."\">Click Here</a> to send another file.";
} else echo "Send a file.\n<form enctype=\"multipart/form-data\" method=\"post\"><input name=\"userfile\" type=\"file\"><input type=\"submit\">";
?>

a quick mod can also loop this for multiple file uploads...

do{
	$newfilename=str_replace(" ","_",$_FILES[key($_FILES)]['name']);
	move_uploaded_file($_FILES[key($_FILES)]['tmp_name'], realpath(".")."/".$newfilename);
	echo "The file <a href=\"".$newfilename."\">".$newfilename."</a> was received.<br>");
} while(next($_FILES));





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users