Mesden Posted June 30, 2010 Share Posted June 30, 2010 Fatal error: Cannot redeclare showuploadform() (previously declared in /hsphere/local/home/aaron21/sc2x.net/file-upload.php:70) in /hsphere/local/home/aaron21/sc2x.net/file-upload.php on line 70 The link is here: http://www.sc2x.net/upload.php I read the Note on Line 70 but it's a little vague, so I thought I'd post the problem here and see if I got any useful information: <?php #################################################################### # File Upload Form 1.1 #################################################################### # For updates visit http://www.zubrag.com/scripts/ #################################################################### #################################################################### # SETTINGS START #################################################################### // Folder to upload files to. Must end with slash / define('DESTINATION_FOLDER','/sc2x.net/rp/'); // Maximum allowed file size, Kb // Set to zero to allow any size define('MAX_FILE_SIZE', 0); // Upload success URL. User will be redirected to this page after upload. define('SUCCESS_URL','http://www.sc2x.net/success.php'); // Allowed file extensions. Will only allow these extensions if not empty. // Example: $exts = array('avi','mov','doc'); $exts = array('SC2Replay'); // rename file after upload? false - leave original, true - rename to some unique filename define('RENAME_FILE', true); // put a string to append to the uploaded file name (after extension); // this will reduce the risk of being hacked by uploading potentially unsafe files; // sample strings: aaa, my, etc. define('APPEND_STRING', ''); // Need uploads log? Logs would be saved in the MySql database. define('DO_LOG', true); // MySql data (in case you want to save uploads log) define('DB_HOST','mysql18.ixwebhosting.com'); // host, usually localhost define('DB_DATABASE','Aaron21_Upload'); // database name define('DB_USERNAME','Aaron21_Uplaod'); // username define('DB_PASSWORD','Bailey001'); // password /* NOTE: when using log, you have to create mysql table first for this script. Copy paste following into your mysql admin tool (like PhpMyAdmin) to create table If you are on cPanel, then prefix _uploads_log on line 205 with your username, so it would be like myusername_uploads_log CREATE TABLE _uploads_log ( log_id int(11) unsigned NOT NULL auto_increment, log_filename varchar(128) default '', log_size int(10) default 0, log_ip varchar(24) default '', log_date timestamp, PRIMARY KEY (log_id), KEY (log_filename) ); */ #################################################################### ### END OF SETTINGS. DO NOT CHANGE BELOW #################################################################### // Allow script to work long enough to upload big files (in seconds, 2 days by default) @set_time_limit(172800); // following may need to be uncommented in case of problems // ini_set("session.gc_maxlifetime","10800"); function showUploadForm($message='') { $max_file_size_tag = ''; if (MAX_FILE_SIZE > 0) { // convert to bytes $max_file_size_tag = "<input name='MAX_FILE_SIZE' value='".(MAX_FILE_SIZE*1024)."' type='hidden' >\n"; } // Load form template include ('file-upload.php'); } // errors list $errors = array(); $message = ''; // we should not exceed php.ini max file size $ini_maxsize = ini_get('upload_max_filesize'); if (!is_numeric($ini_maxsize)) { if (strpos($ini_maxsize, 'M') !== false) $ini_maxsize = intval($ini_maxsize)*1024*1024; elseif (strpos($ini_maxsize, 'K') !== false) $ini_maxsize = intval($ini_maxsize)*1024; elseif (strpos($ini_maxsize, 'G') !== false) $ini_maxsize = intval($ini_maxsize)*1024*1024*1024; } if ($ini_maxsize < MAX_FILE_SIZE*1024) { $errors[] = "Alert! Maximum upload file size in php.ini (upload_max_filesize) is less than script's MAX_FILE_SIZE"; } // show upload form if (!isset($_POST['submit'])) { showUploadForm(join('',$errors)); } // process file upload else { while(true) { // make sure destination folder exists if (!@file_exists(DESTINATION_FOLDER)) { $errors[] = "Destination folder does not exist or no permissions to see it."; break; } // check for upload errors $error_code = $_FILES['filename']['error']; if ($error_code != UPLOAD_ERR_OK) { switch($error_code) { case UPLOAD_ERR_INI_SIZE: // uploaded file exceeds the upload_max_filesize directive in php.ini $errors[] = "File is too big (1)."; break; case UPLOAD_ERR_FORM_SIZE: // uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form $errors[] = "File is too big (2)."; break; case UPLOAD_ERR_PARTIAL: // uploaded file was only partially uploaded. $errors[] = "Could not upload file (1)."; break; case UPLOAD_ERR_NO_FILE: // No file was uploaded $errors[] = "Could not upload file (2)."; break; case UPLOAD_ERR_NO_TMP_DIR: // Missing a temporary folder $errors[] = "Could not upload file (3)."; break; case UPLOAD_ERR_CANT_WRITE: // Failed to write file to disk $errors[] = "Could not upload file (4)."; break; case 8: // File upload stopped by extension $errors[] = "Could not upload file (5)."; break; } // switch // leave the while loop break; } // get file name (not including path) $filename = @basename($_FILES['filename']['name']); // filename of temp uploaded file $tmp_filename = $_FILES['filename']['tmp_name']; $file_ext = @strtolower(@strrchr($filename,".")); if (@strpos($file_ext,'.') === false) { // no dot? strange $errors[] = "Suspicious file name or could not determine file extension."; break; } $file_ext = @substr($file_ext, 1); // remove dot // check file type if needed if (count($exts)) { /// some day maybe check also $_FILES['user_file']['type'] if (!@in_array($file_ext, $exts)) { $errors[] = "Files of this type are not allowed for upload."; break; } } // destination filename, rename if set to $dest_filename = $filename; if (RENAME_FILE) { $dest_filename = md5(uniqid(rand(), true)) . '.' . $file_ext; } // append predefined string for safety $dest_filename = $dest_filename . APPEND_STRING; // get size $filesize = intval($_FILES["filename"]["size"]); // filesize($tmp_filename); // make sure file size is ok if (MAX_FILE_SIZE > 0 && MAX_FILE_SIZE*1024 < $filesize) { $errors[] = "File is too big (3)."; break; } if (!@move_uploaded_file($tmp_filename , DESTINATION_FOLDER . $dest_filename)) { $errors[] = "Could not upload file (6)."; break; } if (DO_LOG) { // Establish DB connection $link = @mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD); if (!$link) { $errors[] = "Could not connect to mysql."; break; } $res = @mysql_select_db(DB_DATABASE, $link); if (!$res) { $errors[] = "Could not select database."; break; } $m_ip = mysql_real_escape_string($_SERVER['REMOTE_ADDR']); $m_size = $filesize; $m_fname = mysql_real_escape_string($dest_filename); $sql = "insert into _uploads_log (log_filename,log_size,log_ip) values ('$m_fname','$m_size','$m_ip')"; $res = @mysql_query($sql); if (!$res) { $errors[] = "Could not run query."; break; } @mysql_free_result($res); @mysql_close($link); } // if (DO_LOG) // redirect to upload success url header('Location: ' . SUCCESS_URL); die(); break; } // while(true) // Errors. Show upload form. $message = join('',$errors); showUploadForm($message); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/206234-upload-form-isnt-working/ Share on other sites More sharing options...
Mesden Posted June 30, 2010 Author Share Posted June 30, 2010 Anyone..? Quote Link to comment https://forums.phpfreaks.com/topic/206234-upload-form-isnt-working/#findComment-1079251 Share on other sites More sharing options...
Adam Posted June 30, 2010 Share Posted June 30, 2010 In file-upload.php you have: function showUploadForm($message='') { $max_file_size_tag = ''; if (MAX_FILE_SIZE > 0) { // convert to bytes $max_file_size_tag = "<input name='MAX_FILE_SIZE' value='".(MAX_FILE_SIZE*1024)."' type='hidden' >\n"; } // Load form template include ('file-upload.php'); } Notice the include at the end, you're including the same file again - which means you're going to declare the function again. There's your problem. NB It's easier to read/copy the code if you place it within tags.. Quote Link to comment https://forums.phpfreaks.com/topic/206234-upload-form-isnt-working/#findComment-1079253 Share on other sites More sharing options...
Mesden Posted June 30, 2010 Author Share Posted June 30, 2010 So what am I supposed to include then..? Quote Link to comment https://forums.phpfreaks.com/topic/206234-upload-form-isnt-working/#findComment-1079256 Share on other sites More sharing options...
Adam Posted June 30, 2010 Share Posted June 30, 2010 Your comment says "Load form template" above the include; the code you've posted doesn't look like a form template to me. Where is the HTML for the form stored? That's probably the file you need to include. Quote Link to comment https://forums.phpfreaks.com/topic/206234-upload-form-isnt-working/#findComment-1079260 Share on other sites More sharing options...
Mesden Posted June 30, 2010 Author Share Posted June 30, 2010 When I link the the web form on upload.php, if I upload a file and press submit all it does is refresh the page. Quote Link to comment https://forums.phpfreaks.com/topic/206234-upload-form-isnt-working/#findComment-1079261 Share on other sites More sharing options...
Adam Posted June 30, 2010 Share Posted June 30, 2010 What's in "upload.php"? Sounds to me like you should be including that file.. Quote Link to comment https://forums.phpfreaks.com/topic/206234-upload-form-isnt-working/#findComment-1079262 Share on other sites More sharing options...
Mesden Posted June 30, 2010 Author Share Posted June 30, 2010 Actually what I said isn't entirely true. If I press submit the URL changed to file-upload.php, but just refreshes the upload page. This is the coding for upload.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>SC2X.Net: Your Premiere Source for Starcraft II!</title> <meta name="keywords" content="Blizzard, Activision, Blizzard-Activision, SC, Starcraft, SC2, Starcraft 2, Starcraft II" /> <meta name="description" content="SC2X.Net is a Fan Site for the much-anticipated Starcraft II. Our objective is to be your premiere source for Starcraft 2 Tournaments." /> <link href="templatemo_style.css" rel="stylesheet" type="text/css" /> <link href="css/jquery.ennui.contentslider.css" rel="stylesheet" type="text/css" media="screen,projection" /> <script language="javascript" type="text/javascript"> function clearText(field) { if (field.defaultValue == field.value) field.value = ''; else if (field.value == '') field.value = field.defaultValue; } </script> </head> <body> <? include 'http://www.sc2x.net/topbar.php' ?> <!-- end of templatemo_site_title_bar_wrapper --> <? include 'http://www.sc2x.net/middlebar.php' ?> <!-- end of templatemo_banner_wrapper_outter --> <div id="templatemo_content"> <div class="section_w940"> <div class="box margin_r_20 box_border"> <h2>Upload Replay</h2> <div class="box_image_wrapper"> <img src="images/folder.png" alt="product 1" /> </div> <p>SC2X.Net has no upcoming Tournaments until the release of Starcraft II: Wings of Liberty.</p> <div class="cleaner_h10"></div> <div class="button_01"><a href="#">More</a></div> </div> <div class="box margin_r_20 box_border"> <h2>Broswse Replays</h2> <div class="box_image_wrapper"> <img src="images/paint.png" alt="product 1" /> </div> <p>Browse through each Season of our Tournaments, their Competitors, and the Champions.</p> <div class="cleaner_h10"></div> <div class="button_01"><a href="http://sc2x.net/phpBB3/viewforum.php?f=15">More</a></div> </div> <div class="box"> <h2>Help & Support</h2> <div class="box_image_wrapper"> <img src="images/safe.png" alt="product 1" /> </div> <p>Contact SC2X.Net for any Comments, Questions or Suggestions you might have.</p> <div class="cleaner_h10"></div> <div class="button_01"><a href="#">More</a></div> </div> <div class="cleaner"> <p> </p> <center> <p> </p></center> <br /> <center> <form id="form1" name="form1" enctype="multipart/form-data" method="post" action="/file-upload.php"> <label> <input name="file" type="file" id="file" size="45" /> </label> <br /> <br /> <br /> By clicking the "Upload" button below, you hereby agree to our<br /> guidelines that are outline in our <a href="/terms.php"> Terms of Use</a>. <br /> <br /> <label> <input name="button" type="submit" class="box_border" id="button" value="Submit" /> </label> </form> </center> <p> <br /> <br /> <br /> <br /> </p> </div> </div> <div class="cleaner_h60"></div> <div class="cleaner"></div> </div> <!-- end of templatemo_content --> <div id="templatemo_footer_wrapper"><br /> <? include 'http://www.sc2x.net/bottombar.php' ?> <!-- end of footer --> </div> <!-- end of footer wrapper --> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/206234-upload-form-isnt-working/#findComment-1079263 Share on other sites More sharing options...
Adam Posted June 30, 2010 Share Posted June 30, 2010 I have to shoot in a moment, so don't have enough time to look into this properly. Try replacing the include file with "upload.php" and see what happens. Good luck! Quote Link to comment https://forums.phpfreaks.com/topic/206234-upload-form-isnt-working/#findComment-1079264 Share on other sites More sharing options...
Mesden Posted June 30, 2010 Author Share Posted June 30, 2010 Yeah as mentioned above I renamed it to upload.php and all it does is send me from /upload.php to /upload-file.php, refreshing the upload page. Quote Link to comment https://forums.phpfreaks.com/topic/206234-upload-form-isnt-working/#findComment-1079266 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.