maxp
December 27th, 2005, 10:25 PM
[Vote Script]
<?
if($_GET['id']){
$currentdate = date("Y-m-d H:i:s");
$sql = "SELECT *
FROM `votes` WHERE `submission` = '$_GET[id]' AND `ip` =
'$_SERVER[REMOTE_ADDR]' AND `time` = '$currentdate'";
$query =
mysql_query($sql, $connect);
if(mysql_num_rows($query)<1){
$row =
mysql_fetch_array($query);
$date = $row['time'];
if($date !=
$currentdate){
$getscore = "SELECT * FROM `flash` WHERE `id` =
'$_GET[id]'";
$gsquery = mysql_query($getscore, $connect);
$gsfetch =
mysql_fetch_array($gsquery);
$currentscore =
$gsfetch['score'];
$numvotes = mysql_num_rows(mysql_query("SELECT * FROM
`votes` WHERE `submission` = '$_GET[id]'"));
$currentavg =
($currentscore*$numvotes);
$newscore =
(($vote+$currentavg)/$numvotes);
$insert = "INSERT INTO `votes` (`ip`,
`submission`, `rating`, `time`) VALUES
('$_SERVER[REMOTE_ADDR]','$_GET[id]','$vote','$currentdate')";
$in
sertquery = mysql_query($insert) or die(mysql_error());
$update =
mysql_query("UPDATE `flash` SET `score` = '$newscore' WHERE id =
'$_GET[id]'") or die(mysql_error());
echo "Thanks for voting! This
submission's score is now <b>$newscore</b>.<br><a
href="view.php?id=$_GET[id]">Back to
submission</a>";
}
}
if(mysql_num_rows($query)>0){
echo "We're
Sorry. You have already voted on this submission today. Come back tomorrow to
vote again.<br><a href="view.php?id='$_GET[id]'">Back to
submission</a>";
}
}
?>
That's my vote script. The votes do
not average right, and go over 5 sometimes. Why is this happening?
Also,
my string generated by date() does not seem to match the ones aleady in the
database when they should.
[Upload Script]
<?
$thefile =
rand(1000,99000).$_FILES['file']['name'];
$thepicfile =
rand(1000,99000).$_FILES['picfile']['name'];
# check to see if the
form is completly filled
if($title == ""){
die("You must enter a
title.<br><a href='submit.php'>Try Again</a>");
}
if($width ==
""){
die("Please specify the width of your movie.<br><a
href='submit.php'>Try Again</a>");
}
if($height == ""){
die("Please specify the height of your movie.<br><a href='submit.php'>Try
Again</a>");
}
if($comments == ""){
die("You need to enter
comments on your movie.<br><a href='submit.php'>Try Again</a>");
}
# Check to see if the file is accessible
if (
!isset($_FILES['file']['name']) || $_FILES['file']['name'] == '' )
{
die('No flash file specified. Please go back and select a file to
upload.');
}
# Check to see if the preview picture is
accessable
if ( !isset($_FILES['picfile']['name']) ||
$_FILES['picfile']['name'] == '' ) {
die('No preview picture file
specified. Please go back and select a preview picture to
upload.');
}
#Define some variables
$filetype =
array("application/x-shockwave-flash");
$picfiletype = array("image/gif",
"image/x-png", "image/png", "image/jpeg", "image/pjpeg");
$pic_upload_path
= '/previews/';
$max_size = 5400000;
# Check to see if the
filesize is too large
if ($_FILES['file']['size'] > $max_size)
{
die('Your flash movie is too large. Please make your filesize smaller
than 5 megabytes.');
}
# Check to see if the filetype is
correct
if (!in_array($_FILES['file']['type'],
$filetype)){
die('Sorry, your file was not an swf file. (Yours was ' .
$_FILES['data']['type'] . ').');
}
# Check to see if the
preview picture filetype is correct
if
(!in_array($_FILES['picfile']['type'], $picfiletype)){
die('Sorry,
your preview picture was not a gif, png, or jpg image.');
}
#
Upload the file and preview picture
function upload($origen,
$destinoDir, $ftemporal) {
$origen =
strtolower(basename($origen));
$destinoFull =
$destinoDir.$origen;
$frand = $origen;
$i = 1;
while
(file_exists( $destinoFull )) {
$file_name = substr($origen,
0, strlen($origen)-4);
$file_extension = substr($origen,
strlen($origen)-4, strlen($origen));
$frand =
$file_name."[$i]".$file_extension;
$destinoFull =
$destinoDir.$frand;
$i++;
}
if
(move_uploaded_file($ftemporal, $destinoFull)) return $frand;
else
return "0";
}
$upload
= upload($_FILES['file']['name'], 'swf',
$_FILES['file']['tmp_name']);
$picupload =
upload($_FILES['picfile']['name'], 'previews',
$_FILES['picfile']['tmp_name']);
# Check to see if upload was
successful
if (!$upload) {
die('Sorry, your file could not be
uploaded. This reason is unknown.');
}
# Check to see if preview
picture upload was successful
if (!$picupload) {
die('Sorry, your
preview picture could not be uploaded. This reason is
unknown.');
}
$title = trim(strip_tags($title));
$date =
date("Y-m-d H:i:s");
$comments = trim(strip_tags($comments));
$sql =
"INSERT INTO `flash` (`name`, `author`, `date`, `type`, `cat`, `revavg`,
`score`, `file`, `picture`, `desc`, `bad`, `audio`, `width`, `height`,
`status`, `content`) VALUES
('$title','$_SESSION[user]','$date','$type','$cat','0','2.5','
$thefile','$thepicfile','$comments','0','$audio',' $width','$heigh
t','pending','$content')";
if (mysql_query($sql, $connect)or
die(mysql_error())) {
echo "File uploaded succesfully.<br><a
href='index.php'>Proceed to flash
listing</a>";
}
?>
Everything goes smoothly here, but when i try
to access the uploads it returns a 404! Is there anthing wrong with
move_uploaded_file()?
<?
if($_GET['id']){
$currentdate = date("Y-m-d H:i:s");
$sql = "SELECT *
FROM `votes` WHERE `submission` = '$_GET[id]' AND `ip` =
'$_SERVER[REMOTE_ADDR]' AND `time` = '$currentdate'";
$query =
mysql_query($sql, $connect);
if(mysql_num_rows($query)<1){
$row =
mysql_fetch_array($query);
$date = $row['time'];
if($date !=
$currentdate){
$getscore = "SELECT * FROM `flash` WHERE `id` =
'$_GET[id]'";
$gsquery = mysql_query($getscore, $connect);
$gsfetch =
mysql_fetch_array($gsquery);
$currentscore =
$gsfetch['score'];
$numvotes = mysql_num_rows(mysql_query("SELECT * FROM
`votes` WHERE `submission` = '$_GET[id]'"));
$currentavg =
($currentscore*$numvotes);
$newscore =
(($vote+$currentavg)/$numvotes);
$insert = "INSERT INTO `votes` (`ip`,
`submission`, `rating`, `time`) VALUES
('$_SERVER[REMOTE_ADDR]','$_GET[id]','$vote','$currentdate')";
$in
sertquery = mysql_query($insert) or die(mysql_error());
$update =
mysql_query("UPDATE `flash` SET `score` = '$newscore' WHERE id =
'$_GET[id]'") or die(mysql_error());
echo "Thanks for voting! This
submission's score is now <b>$newscore</b>.<br><a
href="view.php?id=$_GET[id]">Back to
submission</a>";
}
}
if(mysql_num_rows($query)>0){
echo "We're
Sorry. You have already voted on this submission today. Come back tomorrow to
vote again.<br><a href="view.php?id='$_GET[id]'">Back to
submission</a>";
}
}
?>
That's my vote script. The votes do
not average right, and go over 5 sometimes. Why is this happening?
Also,
my string generated by date() does not seem to match the ones aleady in the
database when they should.
[Upload Script]
<?
$thefile =
rand(1000,99000).$_FILES['file']['name'];
$thepicfile =
rand(1000,99000).$_FILES['picfile']['name'];
# check to see if the
form is completly filled
if($title == ""){
die("You must enter a
title.<br><a href='submit.php'>Try Again</a>");
}
if($width ==
""){
die("Please specify the width of your movie.<br><a
href='submit.php'>Try Again</a>");
}
if($height == ""){
die("Please specify the height of your movie.<br><a href='submit.php'>Try
Again</a>");
}
if($comments == ""){
die("You need to enter
comments on your movie.<br><a href='submit.php'>Try Again</a>");
}
# Check to see if the file is accessible
if (
!isset($_FILES['file']['name']) || $_FILES['file']['name'] == '' )
{
die('No flash file specified. Please go back and select a file to
upload.');
}
# Check to see if the preview picture is
accessable
if ( !isset($_FILES['picfile']['name']) ||
$_FILES['picfile']['name'] == '' ) {
die('No preview picture file
specified. Please go back and select a preview picture to
upload.');
}
#Define some variables
$filetype =
array("application/x-shockwave-flash");
$picfiletype = array("image/gif",
"image/x-png", "image/png", "image/jpeg", "image/pjpeg");
$pic_upload_path
= '/previews/';
$max_size = 5400000;
# Check to see if the
filesize is too large
if ($_FILES['file']['size'] > $max_size)
{
die('Your flash movie is too large. Please make your filesize smaller
than 5 megabytes.');
}
# Check to see if the filetype is
correct
if (!in_array($_FILES['file']['type'],
$filetype)){
die('Sorry, your file was not an swf file. (Yours was ' .
$_FILES['data']['type'] . ').');
}
# Check to see if the
preview picture filetype is correct
if
(!in_array($_FILES['picfile']['type'], $picfiletype)){
die('Sorry,
your preview picture was not a gif, png, or jpg image.');
}
#
Upload the file and preview picture
function upload($origen,
$destinoDir, $ftemporal) {
$origen =
strtolower(basename($origen));
$destinoFull =
$destinoDir.$origen;
$frand = $origen;
$i = 1;
while
(file_exists( $destinoFull )) {
$file_name = substr($origen,
0, strlen($origen)-4);
$file_extension = substr($origen,
strlen($origen)-4, strlen($origen));
$frand =
$file_name."[$i]".$file_extension;
$destinoFull =
$destinoDir.$frand;
$i++;
}
if
(move_uploaded_file($ftemporal, $destinoFull)) return $frand;
else
return "0";
}
$upload
= upload($_FILES['file']['name'], 'swf',
$_FILES['file']['tmp_name']);
$picupload =
upload($_FILES['picfile']['name'], 'previews',
$_FILES['picfile']['tmp_name']);
# Check to see if upload was
successful
if (!$upload) {
die('Sorry, your file could not be
uploaded. This reason is unknown.');
}
# Check to see if preview
picture upload was successful
if (!$picupload) {
die('Sorry, your
preview picture could not be uploaded. This reason is
unknown.');
}
$title = trim(strip_tags($title));
$date =
date("Y-m-d H:i:s");
$comments = trim(strip_tags($comments));
$sql =
"INSERT INTO `flash` (`name`, `author`, `date`, `type`, `cat`, `revavg`,
`score`, `file`, `picture`, `desc`, `bad`, `audio`, `width`, `height`,
`status`, `content`) VALUES
('$title','$_SESSION[user]','$date','$type','$cat','0','2.5','
$thefile','$thepicfile','$comments','0','$audio',' $width','$heigh
t','pending','$content')";
if (mysql_query($sql, $connect)or
die(mysql_error())) {
echo "File uploaded succesfully.<br><a
href='index.php'>Proceed to flash
listing</a>";
}
?>
Everything goes smoothly here, but when i try
to access the uploads it returns a 404! Is there anthing wrong with
move_uploaded_file()?