plugins/SpecialUpdownload.php
changeset 345 4ccdfeee9a11
parent 343 eefe9ab7fe7c
child 366 7e16181545e1
equal deleted inserted replaced
344:be6c5fdd9203 345:4ccdfeee9a11
    31       \'namespace\'=>\'Special\',
    31       \'namespace\'=>\'Special\',
    32       \'special\'=>0,\'visible\'=>1,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\',
    32       \'special\'=>0,\'visible\'=>1,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\',
    33       ));
    33       ));
    34     
    34     
    35     $paths->add_page(Array(
    35     $paths->add_page(Array(
    36       \'name\'=>\'download_file\',
    36       \'name\'=>\'specialpage_download_file\',
    37       \'urlname\'=>\'DownloadFile\',
    37       \'urlname\'=>\'DownloadFile\',
    38       \'namespace\'=>\'Special\',
    38       \'namespace\'=>\'Special\',
    39       \'special\'=>0,\'visible\'=>1,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\',
    39       \'special\'=>0,\'visible\'=>1,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\',
    40       ));
    40       ));
    41     ');
    41     ');
   152       if(!$db->sql_query('DELETE FROM  '.table_prefix.'files WHERE filename=\''.$filename.'\' LIMIT 1;')) $db->_die('The old file data could not be deleted.');
   152       if(!$db->sql_query('DELETE FROM  '.table_prefix.'files WHERE filename=\''.$filename.'\' LIMIT 1;')) $db->_die('The old file data could not be deleted.');
   153     }
   153     }
   154     if(!$db->sql_query('INSERT INTO '.table_prefix.'files(time_id,page_id,filename,size,mimetype,file_extension,file_key) VALUES('.$utime.', \''.$urln.'\', \''.$filename.'\', '.$flen.', \''.$type.'\', \''.$ext.'\', \''.$key.'\')')) $db->_die('The file data entry could not be inserted.');
   154     if(!$db->sql_query('INSERT INTO '.table_prefix.'files(time_id,page_id,filename,size,mimetype,file_extension,file_key) VALUES('.$utime.', \''.$urln.'\', \''.$filename.'\', '.$flen.', \''.$type.'\', \''.$ext.'\', \''.$key.'\')')) $db->_die('The file data entry could not be inserted.');
   155     if(!isset($_POST['update']))
   155     if(!isset($_POST['update']))
   156     {
   156     {
   157       if(!$db->sql_query('INSERT INTO '.table_prefix.'logs(time_id,date_string,log_type,action,author,page_id,namespace) VALUES('.$utime.', \''.date('d M Y h:i a').'\', \'page\', \'create\', \''.$session->username.'\', \''.$filename.'\', \''.'File'.'\');')) $db->_die('The page log could not be updated.');
   157       if(!$db->sql_query('INSERT INTO '.table_prefix.'logs(time_id,date_string,log_type,action,author,page_id,namespace) VALUES('.$utime.', \''.enano_date('d M Y h:i a').'\', \'page\', \'create\', \''.$session->username.'\', \''.$filename.'\', \''.'File'.'\');')) $db->_die('The page log could not be updated.');
   158       if(!$db->sql_query('INSERT INTO '.table_prefix.'pages(name,urlname,namespace,protected,delvotes,delvote_ips) VALUES(\''.$filename.'\', \''.$urln.'\', \'File\', 0, 0, \'\')')) $db->_die('The page listing entry could not be inserted.');
   158       if(!$db->sql_query('INSERT INTO '.table_prefix.'pages(name,urlname,namespace,protected,delvotes,delvote_ips) VALUES(\''.$filename.'\', \''.$urln.'\', \'File\', 0, 0, \'\')')) $db->_die('The page listing entry could not be inserted.');
   159       if(!$db->sql_query('INSERT INTO '.table_prefix.'page_text(page_id,namespace,page_text,char_tag) VALUES(\''.$urln.'\', \'File\', \''.$comments.'\', \''.$chartag.'\')')) $db->_die('The page text entry could not be inserted.');
   159       if(!$db->sql_query('INSERT INTO '.table_prefix.'page_text(page_id,namespace,page_text,char_tag) VALUES(\''.$urln.'\', \'File\', \''.$comments.'\', \''.$chartag.'\')')) $db->_die('The page text entry could not be inserted.');
   160     }
   160     }
   161     else
   161     else
   162     {
   162     {
   163       if(!$db->sql_query('INSERT INTO '.table_prefix.'logs(time_id,date_string,log_type,action,author,page_id,namespace,edit_summary) VALUES('.$utime.', \''.date('d M Y h:i a').'\', \'page\', \'reupload\', \''.$session->username.'\', \''.$filename.'\', \''.'File'.'\', \''.$comments.'\');')) $db->_die('The page log could not be updated.');
   163       if(!$db->sql_query('INSERT INTO '.table_prefix.'logs(time_id,date_string,log_type,action,author,page_id,namespace,edit_summary) VALUES('.$utime.', \''.enano_date('d M Y h:i a').'\', \'page\', \'reupload\', \''.$session->username.'\', \''.$filename.'\', \''.'File'.'\', \''.$comments.'\');')) $db->_die('The page log could not be updated.');
   164     }
   164     }
   165     die_friendly('Upload complete', '<p>Your file has been uploaded successfully. View the <a href="'.makeUrlNS('File', $filename).'">file\'s page</a>.</p>');
   165     die_friendly('Upload complete', '<p>Your file has been uploaded successfully. View the <a href="'.makeUrlNS('File', $filename).'">file\'s page</a>.</p>');
   166   }
   166   }
   167   else
   167   else
   168   {
   168   {
   233     $db->_die('The file data could not be selected.');
   233     $db->_die('The file data could not be selected.');
   234   }
   234   }
   235   if ( $db->numrows() < 1 )
   235   if ( $db->numrows() < 1 )
   236   {
   236   {
   237     header('HTTP/1.1 404 Not Found');
   237     header('HTTP/1.1 404 Not Found');
   238     die_friendly('File not found', '<p>The file "'.$filename.'" cannot be found.</p>');
   238     die_friendly('File not found', '<p>The file "'.htmlspecialchars($filename).'" cannot be found.</p>');
   239   }
   239   }
   240   $row = $db->fetchrow();
   240   $row = $db->fetchrow();
   241   $db->free_result();
   241   $db->free_result();
   242   
   242   
   243   // Check permissions
   243   // Check permissions
   305   if ( isset($_GET['download']) )
   305   if ( isset($_GET['download']) )
   306   {
   306   {
   307     header('Content-disposition: attachment, filename="' . $filename . '";');
   307     header('Content-disposition: attachment, filename="' . $filename . '";');
   308   }
   308   }
   309   header('Content-length: '.$len);
   309   header('Content-length: '.$len);
   310   header('Last-Modified: '.date('r', $row['time_id']));
   310   header('Last-Modified: '.enano_date('r', $row['time_id']));
   311   
   311   
   312   // using this method limits RAM consumption
   312   // using this method limits RAM consumption
   313   while ( !feof($handle) )
   313   while ( !feof($handle) )
   314   {
   314   {
   315     echo fread($handle, 512000);
   315     echo fread($handle, 512000);