|
#1
|
||||
|
||||
|
(Don't know if this is the right place for this, but. . . )
At long last, here is my version of FTP Uploading with PHP. FEATURES: Uploads content, saves info in a table, zip's EXE files, uploads only filetypes you deem safe, simple anti-overwrite feature . . . TO SET UP: FILE: form.php CONTENTS: Code:
<?php
function showform(){
if($_GET['error'] == 1){
$error = '<h3><u>ERROR:</u> You must put a title.</h3>';
}elseif($_GET['error'] == 2){
$error = '<h3><u>ERROR:</u> That file format is not supported.</h3>';
}elseif($_GET['error'] == 3){
$error = '<h3><u>ERROR:</u> Your file failed to load.</h3>';
}elseif($_GET['error'] == 'x'){
$error = '<h3><u>UPLOAD:</u> Your file has been uploaded to the server.</h3>';
}
print " <html>
<head>
<style type='text/css'>
body{
text-align: center;
}div#left, div#right{
float: left;
width: 300px;
height: 300px;
}div#base{
float: left;
width: 600px;
border-style: solid;
border-color: #000000;
border-width: 1 0 1 0;
text-align: center;
}p{
text-align: justify;
text-indent: 30px;
margin: 0;
}div#terms{
width: 600px;
margin-right: auto;
margin-left: auto;
}div#form{ width: 600px; display: none; text-align: left; margin: auto; }
</style>
<script type='text/javascript'>
<!--
function agree(){
document.getElementById('terms').style.display = 'none';
document.getElementById('form').style.display = 'block';
}
//-->
</script>
</head>
<body>
<div id='terms'>
<!--========================================//-->
<div style='width:600px; margin:auto; font-size:1px;'>$error</div>
<h2><p style='text-align: center'>TERMS OF USE:</p></h2>
<hr></hr>
<p>YOUR TERMS OF USE GO HERE</p>
<p style='text-align: center'>I agree:<input type='radio' onclick=agree() name='1'>
I disagree:<input type='radio' onclick='javascript:history.back()' name='1'></p>
<!--========================================//-->
</div>
<div id='form'>
<form name='upload' enctype='multipart/form-data' action='upload.php' method='POST'>
<h2>Submit Information</h2>
<div id='left'>
File To Upload:<br>
<input type='file' name='up_file'><br>
Title:<br>
<input type='text' name='title'><br>
Description:<br>
<textarea name='discription'></textarea><br>
</div>
<div id='right'>
Notes:<br>
<textarea name='notes'></textarea><br>
Copyright:<br>
<input type='text' name='copyright'><br>
</div>
<div id='base'>
<input type='submit' name='Submit' value='Submit'>
<input type='reset' value='Reset'>
<input type=hidden name=box value=''>
</div>
</form>
</div>
Script by: Jason Mace 2007
</body>
</html>";
}
?>
(NOTE THAT THIS IS THE FILE THAT SHOULD BE VIEWED) CONTENTS: Code:
<?php
$Connection = MySQL_Connect($host, $name, $pass) or die ('NO CONNECTION TO MySQL');
if (!MySQL_Select_db('Files')){
print 'Create DB: '. mysql_query('CREATE DATABASE Files');
print '<br>Select DB: '.MySQL_Select_db('Files');
print '<br>Create Table: '.
MySQL_query("CREATE TABLE files (
num SERIAL,
path VARCHAR(150),
title VARCHAR(100),
filetype VARCHAR(20),
disc VARCHAR(500),
provider VARCHAR(50),
notes VARCHAR(500),
copyright VARCHAR(150)
);");
}else{}
if ($_POST['Submit'] == 'Submit'){
if($_POST['title'] == ''){
header("Location: ./upload.php?error=1");
}else{
set_time_limit(0);
$conn_id = ftp_connect($host) or die("Couldn't connect");
$login_result = ftp_login($conn_id, $ftpName, $ftpPass) or die("ERROR IN FTP CONNECTION");
$theFile = $_FILES['up_file'];
$source = $theFile['tmp_name'];
$file_destination = $_FILES['up_file']['name'];
$allowedTYPES = array('JPEG','JPG','AVI','MPEG','WMV','PDF','DOC','DOCX','TXT','EXE','ZIP');
$filetype = pathinfo($_FILES['up_file']['name']);
$filetype = strtoupper($filetype['extension']);
if(array_search($filetype, $allowedTYPES)){
ftp_chdir($conn_id, "/information/");
ftp_chdir($conn_id, "upload");
$path = './information/upload/';
$i = 0;
while(is_file('./upload/'.$file_destination) == 1){
$file_destination = $i.$file_destination;
$i++;
}
$path2= '/upload/'.$file_destination;
$upload = ftp_put($conn_id, $file_destination, $source, FTP_BINARY);
if($filetype == 'EXE'){
$zip = new ZipArchive;
$res = $zip->open("./upload/$file_destination.zip", ZipArchive::CREATE);
if ($res === TRUE) {
$zip->addFile("./upload/$file_destination", $file_destination);
$zip->close();
unlink("./upload/$file_destination");
$path2 .= '.zip';
} else {
$upload = false;
}
}else{}
if($upload){
$title = $_POST['title'];
$disc = $_POST['discription'];
$provider = $_SESSION['username'];
$notes = $_POST['notes'];
$copyright = $_POST['copyright'];
MySQL_Query("INSERT INTO files VALUES(
NULL,
'$path2',
'$title',
'$filetype',
'$style',
'$disc',
'$sugrank',
'$provider',
'$notes',
'$copyright'
)");
header("Location: ./upload.php?error=x");
}else{ header("Location: ./upload.php?error=3"); }
}else{ header("Location: ./upload.php?error=2&filetype=$filetype");}
MySQL_Close($Connection);
ftp_close($conn_id);
}
} else {
showform();
}
?>
Code:
php_value upload_max_filesize 50M *All the things in red should be changed. If you have any questions, feel free to post them. And, I did spend several months creating this, so an "Upload Script by Jason Mace" somewhere on the site would be great-- You don't have to, of course. . .
__________________
--Jas function GreatMinds(){ return "Think Like Jas"; }
Last edited by Jas; 11-08-2007 at 09:42 PM. |
|
#2
|
|||
|
|||
|
So if I understand this right I can upload large video files right? Up to how big would you say?
Also, what is it asking for when it says $conn_id above in your upload.php code? Also, where would the .htaccess file be in the ftp server? One last thing, I have copied and pasted the two portions of code and tried to bring up the form and nothing comes up. What could be the problem? Last edited by pssparkman; 11-07-2007 at 10:25 PM. |
|
#3
|
||||
|
||||
|
Quote:
Code:
php_value upload_max_filesize 50M Quote:
.htaccess is a file on the server (named .htaccess) that contains settings for your webserver--it's not part of the FTP server. If you don't have one on your webserver yet, create one. Put the code into the file and name it .htacces and put it in the root folder. As for the last question, are you viewing the upload.php file? (Not the form.php file.)
__________________
--Jas function GreatMinds(){ return "Think Like Jas"; }
Last edited by Jas; 11-08-2007 at 12:28 AM. |
|
#4
|
|||
|
|||
|
I went to view the form.php and it displayed nothing on the screen. I copied and pasted the form.php code exactly as you had it and then went to view it in the browser and nothing came up.
As for the $conn_id do I need to replace that with anything. I still don't understand. Sorry, as my coding skills just simply suck. The 50MB file size is actually too small for the video files that I need to uploaded. Will it handle say up to 100-200MB files? Thanks. |
|
#5
|
||||
|
||||
|
Quote:
Quote:
Quote:
Did you figure out everything else okay?
__________________
--Jas function GreatMinds(){ return "Think Like Jas"; }
Last edited by Jas; 11-08-2007 at 05:04 AM. |
|
#6
|
|||
|
|||
|
Yeah, everything is pretty explanatory.
When trying to view it, this came up: Code:
Parse error: parse error, unexpected ')', expecting '(' in .........
Code:
$res = $zip->open("./uploads/$file_destination.zip", ZipArchive::CREATE);
Last edited by pssparkman; 11-08-2007 at 07:21 AM. |
|
#7
|
||||
|
||||
|
It might be that you need to enable that feature in you PHP ini file. The easiest way to do that is to click the wamp server quicklink on the taskbar>> PHP Settings >> Extensions >> PHP_zip
EDIT: There was also an error in the file location. Try replacing the zip portion of code as well (I fixed it). EDIT2: Actually, replace the whole file. There was another location error for the MySQL area. ![]() Try enabing that, replacing the code, and If it doesn't work, give me the full error message and I'll see what I can do from there.
__________________
--Jas function GreatMinds(){ return "Think Like Jas"; }
Last edited by Jas; 11-08-2007 at 09:43 PM. |
|
#8
|
|||
|
|||
|
for somereason, i get a 500 internal error when i put the .htaccess in my file, why is this, i dont understand it..
|
|
#9
|
|||
|
|||
|
Jas, what file type does the .htaccess have to be? (htm, php, html, etc.)
|
|
#10
|
|||
|
|||
|
.htaccess is its own file..
put that htaccess code into a notepad. save as name= .htaccess and make sure it says .htaccess only.. it should not say .htaccess.txt or anything just .htaccess... |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
|
|