Looking for a good php upload script, please help?
Hello,
I need a good uploading script that will upload any size file and let me choose what kind of files to upload. Doesn’t have to be PHP, but preferred. Not looking for anything free unless it’s just too cool. I would like it to display a jpeg, resized image after for confirmation. You are welcome to send quotes if you think you can create one. Thanks in advance!
August 19, 2010 | Filed Under Scripts FAQs
Comments
One Response to “Looking for a good php upload script, please help?”
Powered by Yahoo! Answers
Here is a complete solution for uploading files
Requirements:
PHP
MYSQL
Write access to directory tree
2 Database tables (files, mime_types)SQL below
Code:
–
– Table structure for table `mime_types`
–
DROP TABLE IF EXISTS `mime_types`;
CREATE TABLE IF NOT EXISTS `mime_types` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`extension` varchar(5) NOT NULL,
`type` varchar(100) NOT NULL,
`aud_vid` int(11) NOT NULL,
`access_type` int(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=41 ;
–
– Dumping data for table `mime_types`
–
INSERT INTO `mime_types` (`id`, `extension`, `type`, `aud_vid`, `access_type`) VALUES
(1, ‘.au’, ‘audio/basic’, 1, 1),
(2, ‘.avi’, ‘application/x-troff-msvideo’, 1, 0),
(3, ‘.bm’, ‘image/bmp’, 0, 1),
(4, ‘.bmp’, ‘image/bmp’, 0, 1),
(5, ‘.doc’, ‘application/msword’, 0, 0),
(6, ‘.flp’, ‘application/FruityLoops Project’, 1, 1),
(7, ‘.gif’, ‘image/gif’, 0, 1),
(8, ‘.gz’, ‘application/x-gzip’, 0, 0),
(9, ‘.gzip’, ‘application/x-gzip’, 0, 0),
(10, ‘.jpe’, ‘image/jpeg’, 0, 1),
(11, ‘.jpeg’, ‘image/jpeg’, 0, 1),
(12, ‘.jpg’, ‘image/jpeg’, 0, 1),
(13, ‘.kar’, ‘audio/midi’, 1, 1),
(14, ‘.mid’, ‘audio/midi’, 1, 1),
(15, ‘.mov’, ‘video/quicktime’, 1, 0),
(16, ‘.mp2′, ‘audio/mpeg’, 1, 1),
(17, ‘.mp3′, ‘audio/mpeg3′, 1, 1),
(18, ‘.mpa’, ‘audio/mpeg’, 1, 1),
(19, ‘.mpe’, ‘video/mpeg’, 1, 1),
(20, ‘.mpeg’, ‘video/mpeg’, 1, 0),
(21, ‘.mpg’, ‘video/mpeg’, 1, 0),
(22, ‘.pdf’, ‘application/pdf’, 0, 0),
(23, ‘.png’, ‘image/png’, 0, 1),
(24, ‘.ppt’, ‘application/mspowerpoint’, 0, 0),
(25, ‘.qt’, ‘video/quicktime’, 1, 0),
(26, ‘.ra’, ‘audio/x-pn-realaudio’, 1, 1),
(27, ‘.ram’, ‘audio/x-pn-realaudio’, 1, 1),
(28, ‘.rmi’, ‘audio/mid’, 1, 1),
(29, ‘.rtx’, ‘application/rtf’, 0, 0),
(30, ‘.swf’, ‘application/x-shockwave-flash’, 0, 0),
(31, ‘.tif’, ‘image/tiff’, 0, 1),
(32, ‘.tiff’, ‘image/tiff’, 0, 1),
(33, ‘.txt’, ‘text/plain’, 0, 0),
(34, ‘.wav’, ‘audio/wav’, 1, 1),
(35, ‘.wma’, ‘audio/x-ms-wma’, 1, 1),
(36, ‘.wmv’, ‘video/x-ms-wmv’, 1, 0),
(37, ‘.xls’, ‘application/excel’, 0, 0),
(38, ‘.zip’, ‘application/zip’, 0, 0),
(39, ‘.mp3′, ‘audio/x-mpeg’, 1, 1),
(40, ‘.ppt’, ‘application/vnd.ms-powerpoint’, 0, 0);
Code:
–
– Table structure for table `files`
–
DROP TABLE IF EXISTS `files`;
CREATE TABLE IF NOT EXISTS `files` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT ‘DB user ID’,
`UID` varchar(32) NOT NULL COMMENT ‘user id’,
`File_Name` varchar(255) NOT NULL COMMENT ‘file name’,
`File_ID` varchar(32) NOT NULL COMMENT ‘file ID’,
`File_Type` varchar(50) NOT NULL COMMENT ‘MIME type’,
`File_Path` varchar(255) NOT NULL COMMENT ‘relative path to file’,
`File_Access` int(1) NOT NULL COMMENT ‘access level of file’,
`File_DTG` varchar(100) NOT NULL COMMENT ‘file upload date time group’,
`File_Size` varchar(11) NOT NULL,
`Read_File_Size` varchar(10) NOT NULL,
`File_Count` int(11) NOT NULL COMMENT ‘file views’,
`Comments` longtext NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Code:
<?
/********************************
files.class.php
********************************/
class files{
var $Error;
var $goback;
function files(){
}
function file_form($UserInput){
echo "<div align=\"center\"><form method=\"post\" action=\"$_SERVER[PHP_SELF]\" name=\"FileUpload\" enctype=\"multipart/form-data\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" id=\"LoginTable\" bgcolor=\"#000000\" align=\"center\"><tr><td id=\"Upload\"><strong>**Information**</strong><br><i>Max upload file size is 10MB</i><br><br></td></tr><tr><td id=\"Upload\"><div align=\"center\">File to upload: <input type=\"file\" name=\"file_to_upload\"></div></td></tr><tr><td id=\"Upload\"><div align=\"center\">Access: <select name=\"Access\" id=\"select\"><option value=\"0\">Private</option><option value=\"1\">Public</option></select></div></td></tr><tr><td id=\"Upload\"><div align=\"center\">File Comments:</div></td></tr><tr><td colspan=\"2\" id=\"Upload\"><div align=\"center\"><textarea name=\"FileComments\" cols=\"50\" rows=\"10\"></textarea></div></td></tr><tr><td id=\"Upload\" colspan=\"2\"><div align=\"center\"><input type=\"submit\" value=\"Submit\"> <input type=\"reset\" value=\"Reset\"></div></td></tr></table></form></div>";
}
function add_file($UserInput){
require_once(‘static.class.php’);
if(file_exists("upload/" . $_FILES['file_to_upload']['name']))
{
$this->file_form($UserInput);
echo "<div align=\"center\"><font color=\"red\">The file already exists! Delete first!<br>Try again or $this->goback!</font></div>";
$this->Error == true;
exit;
}
else
{
//Add the file
$this->move_temp_file = move_uploaded_file($_FILES['file_to_upload']['tmp_name'], "upload/" . $_FILES['file_to_upload']['name']);
if(!$this->move_temp_file)
{
$this->file_form($UserInput);
echo "<div align=\"center\"><font color=\"red\">There was a problem uploading your file!<br>Try again or $this->goback!<br>Contact support!</font></div>";
$this->Error == true;
exit;
}
else
{
//Add file information to database
//Generate File ID
$this->file_ID = md5($_SESSION['Path'] . "/" . $_FILES['file_to_upload']['name'] . date($_SESSION['UNIX_EP']));
$this->file_path = $_SESSION['Path'] . "/" . $_FILES['file_to_upload']['name'];
$Nfile_name = $_FILES['file_to_upload']['name'];
$Nfile_type = $_FILES['file_to_upload']['type'];
$Nfile_size = $_FILES['file_to_upload']['size'];
$IVal = $_FILES['file_to_upload']['size'];
$file_size = new static_class();
$file_size->StaticFSize($IVal);
$this->read_file_size = $file_size->FDS;
$this->query_string = "INSERT INTO files (id, UID, File_Name, File_ID, File_Type, File_Path, File_Access, File_DTG, File_Size, Read_File_Size, File_Count, Comments) VALUES(’0′,’$_SESSION[UID]‘, ‘$Nfile_name’,'$this->file_ID’,'$Nfile_type’,'$this->file_path’,'$UserInput[Access]‘,’" . date($_SESSION['DTG']) . "’,'$Nfile_size’,'$this->read_file_size’,’0′,’" . addslashes($UserInput['FileComments']) . "’)";
$this->query = mysql_query($this->query_string);
if(!$this->query)
{
$this->delete_file = unlink("upload/" . $_FILES['file_to_upload']['name']);
$this->file_form($UserInput);
$space_left_message = ($this->space_left <= "0") ? "You do not have any space left" : "Space left:" . $file_size->FDS;
echo "<div align=\"center\"><font color=\"red\">Error adding file to database! No file uploaded! $this->goback</font></div>";
$this->Error == true;
exit;
}
else
{
$this->file_form($UserInput);
echo "<div align=\"center\"><font color=\"red\">File upload complete!</font>&