Changeset 45 for branches/download
- Timestamp:
- 02/14/09 11:18:08 (3 years ago)
- Location:
- branches/download
- Files:
-
- 4 modified
-
admin/download.php (modified) (3 diffs)
-
download.php (modified) (3 diffs)
-
install.php (modified) (1 diff)
-
submit_download.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/download/admin/download.php
r34 r45 210 210 $approved = isset($_POST['approved']) ? 1 : 0; 211 211 212 212 213 if ($name == '') 213 214 message($lang_admin_download['Must enter download message']); 214 215 215 if (is_uploaded_file($_FILES['file_upload']['tmp_name'])) 216 217 /* if (is_uploaded_file($_FILES['file_upload']['tmp_name'])) 216 218 { 217 219 $file_upload = $_FILES['file_upload']['name']; … … 223 225 move_uploaded_file($_FILES['file_upload']['tmp_name'], DOWNLOAD.'files/'.$download_id.'.zip'); 224 226 } 227 */ 225 228 226 /* if (isset($_FILES['file_upload']) && is_uploaded_file($_FILES['file_upload']['tmp_name'])) 229 $query = array( 230 'UPDATE' => 'downloads', 231 'SET' => 'name=\''.$forum_db->escape($name).'\', description=\''.$forum_db->escape($description).'\', cat='.$cat.', version=\''.$forum_db->escape($version).'\', author=\''.$forum_db->escape($author).'\', approved='.$approved, 232 'WHERE' => 'id='.$download_id 233 ); 234 235 if (isset($_FILES['file_upload']) && is_uploaded_file($_FILES['file_upload']['tmp_name'])) 227 236 { 228 237 $file_upload = $_FILES['file_upload']['name']; 229 238 $file_ext = substr($file_upload, strrpos($file_upload, '.')+1); 230 239 231 if ($file_ext != 'zip') 240 $allowed_ext = array('zip', 'rar'); 241 if (!in_array($file_ext, $allowed_ext)) 232 242 message($lang_admin_download['Invalid extension']); 233 243 … … 246 256 $file = $_FILES['file_upload']['name']; 247 257 258 $file = str_replace(' ', '_', strtolower($file)); 259 $file = preg_replace('/[^0-9a-z\._]/', '', $file); 260 248 261 move_uploaded_file($_FILES['file_upload']['tmp_name'], DOWNLOAD.'files/'.$file); 249 }*/ 250 251 $query = array( 252 'UPDATE' => 'downloads', 253 'SET' => 'name=\''.$forum_db->escape($name).'\', description=\''.$forum_db->escape($description).'\', cat='.$cat.', version=\''.$forum_db->escape($version).'\', author=\''.$forum_db->escape($author).'\', approved='.$approved, 254 'WHERE' => 'id='.$download_id 255 ); 256 257 // If uploaded new file, reset downloads counter 258 if (isset($_FILES['file_upload']) && is_uploaded_file($_FILES['file_upload']['tmp_name'])) 259 $query['SET'] .= ', downloads=0'; 262 $query['SET'] .= ', downloads=0, file=\''.$forum_db->escape($file).'\''; 263 } 260 264 261 265 ($hook = get_hook('afo_save_forum_qr_update_forum')) ? (defined('FORUM_USE_INCLUDE') ? include $hook : eval($hook)) : null; -
branches/download/download.php
r34 r45 24 24 // Fetch list of downloads 25 25 $query = array( 26 'SELECT' => 'd.name, d.version ',26 'SELECT' => 'd.name, d.version, d.file', 27 27 'FROM' => 'downloads AS d', 28 28 'WHERE' => 'd.id=\''.$id.'\'', … … 41 41 $cur_file = $forum_db->fetch_assoc($result); 42 42 43 $file = DOWNLOAD.'files/'.$id.'.zip'; 44 45 if (!file_exists($file)) 43 if (!file_exists(DOWNLOAD.'files/'.$cur_file['file'])) 46 44 message($lang_download['File not found']); 47 45 … … 56 54 $result = $forum_db->query_build($query) or error(__FILE__, __LINE__); 57 55 58 $version = ($cur_file['version'] != '' ? '_'.$cur_file['version'] : ''); 59 $url = strtolower($cur_file['name'].$version.'.zip'); 60 $url = str_replace(' ', '_', $url); 61 $url = preg_replace('/[^0-9a-z\._]/', '', $url); 62 63 //@ob_end_clean(); //turn off output buffering to decrease cpu usage 64 header('Content-Type: application/zip'); 56 // $version = ($cur_file['version'] != '' ? '_'.$cur_file['version'] : ''); 57 /* $filename = str_replace(' ', '_', $filename); 58 $filename = preg_replace('/[^0-9a-z\._]/', '', $filename); 59 */ 60 61 /* header('Content-Type: application/zip'); 65 62 header('Content-Disposition: attachment; filename="'.rawurldecode($url).'"'); 66 /* header("Content-Transfer-Encoding: binary"); 67 header('Accept-Ranges: bytes');*/ 63 header("Content-Transfer-Encoding: binary"); 68 64 header("Content-Length: ".filesize($file)); 69 65 70 66 // The three lines below basically make the download non-cacheable 71 header("Cache-control: private"); 67 header("Cache-control: public"); 68 header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 72 69 header('Pragma: private'); 73 70 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 74 75 $chunksize = 1*(1024*1024); //you may want to change this 76 if ($file = fopen($file, 'r')) 77 { 78 if(isset($_SERVER['HTTP_RANGE'])) 79 fseek($file, $range); 80 81 while(!feof($file)) 82 { 83 $buffer = fread($file, $chunksize); 84 print($buffer); //echo($buffer); // is also possible 85 flush(); 86 $bytes_send += strlen($buffer); 87 } 88 fclose($file); 89 } 90 else 91 message('Error - can not open file.'); 92 71 72 readfile($file);*/ 73 74 header('Location: '.$base_url.'/extensions/download/files/'.$cur_file['file']); 93 75 exit; 76 94 77 } 95 78 elseif (isset($cat)) -
branches/download/install.php
r13 r45 21 21 { 22 22 // do upgrade... 23 if (EXT_CUR_VERSION == '1.0') 24 { 25 $forum_db->add_field('downloads', 'file', 'VARCHAR(255)', false); 23 26 27 $query = array( 28 'SELECT' => 'name, version, id', 29 'FROM' => 'downloads', 30 ); 31 $result = $forum_db->query_build($query) or error(__FILE__, __LINE__); 32 33 while ($cur_download = $forum_db->fetch_assoc($result)) 34 { 35 $version = ($cur_download['version'] != '' ? '_'.$cur_download['version'] : ''); 36 $filename = $cur_download['name'].$version.'.zip'; 37 $filename = str_replace(' ', '_', strtolower($filename)); 38 $filename = preg_replace('/[^0-9a-z\._]/', '', $filename); 39 40 $query2 = array( 41 'UPDATE' => 'downloads', 42 'SET' => 'file=\''.$forum_db->escape($filename).'\'', 43 'WHERE' => 'id=\''.$cur_download['id'].'\'', 44 ); 45 $result2 = $forum_db->query_build($query2) or error(__FILE__, __LINE__); 46 47 rename(FORUM_ROOT.'extensions/download/files/'.$cur_download['id'].'.zip', FORUM_ROOT.'extensions/download/files/'.$filename); 48 } 49 50 } 24 51 25 52 } -
branches/download/submit_download.php
r29 r45 44 44 $file_ext = substr($file_upload, strrpos($file_upload, '.')+1); 45 45 46 if ($file_ext != 'zip') 46 $allowed_ext = array('zip', 'rar'); 47 if (!in_array($file_ext, $allowed_ext)) 47 48 message($lang_admin_download['Invalid extension']); 48 49 49 /* if (file_exists(DOWNLOAD.'files/'.$file_upload)) 50 { 51 // Get new name for file 52 $filename = substr($file_upload, 0, strrpos($file_upload, '.')); 53 $ext = substr($file_upload, strrpos($file_upload, '.')); 54 $i = 1; 55 while (file_exists(DOWNLOAD.'files/'.$filename.'_'.$i.$ext)) 56 $i++; 57 $file = $filename.'_'.$i.$ext; 58 } 59 else 60 $file = $_FILES['file_upload']['name'];*/ 50 if (file_exists(DOWNLOAD.'files/'.$file_upload)) 51 { 52 // Get new name for file 53 $filename = substr($file_upload, 0, strrpos($file_upload, '.')); 54 $ext = substr($file_upload, strrpos($file_upload, '.')); 55 $i = 1; 56 while (file_exists(DOWNLOAD.'files/'.$filename.'_'.$i.$ext)) 57 $i++; 58 $file = $filename.'_'.$i.$ext; 59 } 60 else 61 $file = $_FILES['file_upload']['name']; 62 63 $file = str_replace(' ', '_', strtolower($file)); 64 $file = preg_replace('/[^0-9a-z\._]/', '', $file); 65 66 move_uploaded_file($_FILES['file_upload']['tmp_name'], DOWNLOAD.'files/'.$file); 61 67 62 68 $query = array( 63 'INSERT' => 'name, description, cat, author, version, user_id, added ',69 'INSERT' => 'name, description, cat, author, version, user_id, added, file', 64 70 'INTO' => 'downloads', 65 'VALUES' => '\''.$forum_db->escape($name).'\', \''.$forum_db->escape($description).'\', '.$cat.', \''.$forum_db->escape($author).'\', \''.$forum_db->escape($version).'\', \''.$forum_db->escape($forum_user['id']).'\', '.time() ,71 'VALUES' => '\''.$forum_db->escape($name).'\', \''.$forum_db->escape($description).'\', '.$cat.', \''.$forum_db->escape($author).'\', \''.$forum_db->escape($version).'\', \''.$forum_db->escape($forum_user['id']).'\', '.time().', \''.$forum_db->escape($file).'\'', 66 72 ); 67 73 … … 74 80 ($hook = get_hook('afo_save_forum_qr_update_forum')) ? (defined('FORUM_USE_INCLUDE') ? include $hook : eval($hook)) : null; 75 81 $forum_db->query_build($query) or error(__FILE__, __LINE__); 76 77 move_uploaded_file($_FILES['file_upload']['tmp_name'], DOWNLOAD.'files/'.$forum_db->insert_id().'.zip');78 82 79 83 ($hook = get_hook('afo_save_forum_pre_redirect')) ? (defined('FORUM_USE_INCLUDE') ? include $hook : eval($hook)) : null;