Rockonmetal
07-15-2007, 11:34 PM
Hey was up guys...
So I am planning on making the next YouTube *called PUREADD!*. Though heres the thing I don't want the video to go on its own webpage. Basicly I am just asking how to validate this in someway. I have a simple upload tag in there which uploads it to a folder named "Uploads". But as most of you can see. Anyone can upload anyfile less than 1Gb. *I have that Hidden Input in there which works.* So I could get a ton of .html, php, even images instead of funny videos.
I do not know how to do this. I tried PHP Freaks and their tutorial did not work. It wouldn't upload. I got this off of Tenzig or something like that. It works. Just I don't know how to validate this.
<html>
<head>
</head>
<body>
<?php
$var = $_POST["text"];
$var2 = $_POST["text2"];
$var3 = $_POST["text3"];
$var4 = $_POST["text4"];
$var5 = $_POST["text5"];
$var6 = $_POST["text6"];
$var7 = $_POST["uploadedfile"];
echo "Please Fill Out The Form Below"
?>
<?php
$filename = 'data.html';
$somecontent = "
<br>
<table class='data'>
<tr><td>Name:</td><td> $var</td>
<tr><td>Email Address:</td><td> $var2</td>
<tr><td>Password:</td><td> $var3</td>
<tr><td>Comfirmed Password:</td><td> $var4</td></tr>
<tr><td>Video Notes:</td><td> $var5</td></tr>
<tr><td>Agree to Terms:</td><td> $var6</td></tr>
<tr><td>File Name:</td><td> $var7</td></tr>
</table>
<br>";
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "<br>Success, your content to the database. Do not refresh the page or your entry will be deleted.";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file.";
}
?>
</body>
</html>
BTW! I can learn pretty easily. Just as long as the code isn't 400 pages or is all on one line *I CANNOT STAND THAT!* I was having one problem also. If two files get uploaded with the same name the one that was uploaded 2nd would overwrite the first... If theres anyway I could make a sorta check if/else statement to rename the file being uploaded.
THANKS SO MUCH!
So I am planning on making the next YouTube *called PUREADD!*. Though heres the thing I don't want the video to go on its own webpage. Basicly I am just asking how to validate this in someway. I have a simple upload tag in there which uploads it to a folder named "Uploads". But as most of you can see. Anyone can upload anyfile less than 1Gb. *I have that Hidden Input in there which works.* So I could get a ton of .html, php, even images instead of funny videos.
I do not know how to do this. I tried PHP Freaks and their tutorial did not work. It wouldn't upload. I got this off of Tenzig or something like that. It works. Just I don't know how to validate this.
<html>
<head>
</head>
<body>
<?php
$var = $_POST["text"];
$var2 = $_POST["text2"];
$var3 = $_POST["text3"];
$var4 = $_POST["text4"];
$var5 = $_POST["text5"];
$var6 = $_POST["text6"];
$var7 = $_POST["uploadedfile"];
echo "Please Fill Out The Form Below"
?>
<?php
$filename = 'data.html';
$somecontent = "
<br>
<table class='data'>
<tr><td>Name:</td><td> $var</td>
<tr><td>Email Address:</td><td> $var2</td>
<tr><td>Password:</td><td> $var3</td>
<tr><td>Comfirmed Password:</td><td> $var4</td></tr>
<tr><td>Video Notes:</td><td> $var5</td></tr>
<tr><td>Agree to Terms:</td><td> $var6</td></tr>
<tr><td>File Name:</td><td> $var7</td></tr>
</table>
<br>";
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "<br>Success, your content to the database. Do not refresh the page or your entry will be deleted.";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file.";
}
?>
</body>
</html>
BTW! I can learn pretty easily. Just as long as the code isn't 400 pages or is all on one line *I CANNOT STAND THAT!* I was having one problem also. If two files get uploaded with the same name the one that was uploaded 2nd would overwrite the first... If theres anyway I could make a sorta check if/else statement to rename the file being uploaded.
THANKS SO MUCH!