Chrisj Posted May 23, 2007 Share Posted May 23, 2007 I'm hoping someone might be interested in helping me add add a browse/upload-file field into an existing log-in page. Plus, store the file size in a database to keep track of how much each registered user uploads, change the file name, and limit the uploaded file to a handful of extensions. I have this code: <?php if (isset($_SESSION['customer_id'])) { echo ' <form action="/WHEREVER IM GOING/" enctype="multipart/form-data" method="post"> <p> Please specify a filebr /> <input type="file" name="myfile" size="40"> </p> <p> <input type="submit" value="Send"> </p> </form>'; } if (!empty($_FILES)) { $connection = mysql_connect("hostname", "username", "password"); $db = mysql_select_db("dbname", $connection); mysql_query("INSERT INTO upload_track (customer_id, filesize) VALUES (" . $_SESSION['customer_id'] . ", " . $_FILES['myfile']['size'] . ")", $connection); } ?> And this code: move_uploaded_file([uploadedfile],[path/to/filename.ext]); and the log-in page code below. I just don't know how to put them together to make them function together with what I'd like the form to do, as outlined above. Would anyone like to provide me with some assistance/guidance here? Thank you. <?php /* +-------------------------------------------------------------------------- | login.inc.php | ======================================== | Start the session +-------------------------------------------------------------------------- */ if (eregi(".inc.php",$HTTP_SERVER_VARS['PHP_SELF']) || eregi(".inc.php",$_SERVER['PHP_SELF'])) { echo "<html>\r\n<head>\r\n<title>Forbidden 403</title>\r\n</head>\r\n<body><h3>Forbidden 403</h3>\r\nThe document you are requesting is forbidden.\r\n</body>\r\n</html>"; exit; } $_GET['act'] = treatGet($_GET['act']); if($_GET['act']=="login" && isset($_POST['username']) && isset($_POST['password'])){ $_POST['username'] = treatGet($_POST['username']); $_POST['password'] = treatGet($_POST['password']); $query = "SELECT customer_id FROM ".$glob['dbprefix']."CubeCart_customer WHERE email=".$db->mySQLSafe($_POST['username'])." AND password = ".$db->mySQLSafe(md5($_POST['password']))." AND type>0"; $customer = $db->select($query); if($customer==FALSE) { if($db->blocker($_POST['username'],$ini['bfattempts'],$ini['bftime'],FALSE,"f")==TRUE) { $blocked = TRUE; } } elseif($customer[0]['customer_id']>0) { if($db->blocker($_POST['username'],$ini['bfattempts'],$ini['bftime'],TRUE,"f")==TRUE) { $blocked = TRUE; } else { $customerData["customer_id"] = $customer[0]['customer_id']; $update = $db->update($glob['dbprefix']."CubeCart_sessions", $customerData,"sessId=".$db->mySQLSafe($_SESSION['ccUser'])); $_POST['remember'] = treatGet($_POST['remember']); if($_POST['remember']==1){ setcookie("ccRemember","1",time()+$config['sqlSessionExpiry'], $GLOBALS['rootRel']); } // redirect // "login","reg","unsubscribe","forgotPass" if(isset($_GET['redir']) && !empty($_GET['redir']) && !eregi("logout|login|forgotPass|changePass",base64_decode($_GET['redir']))){ header("Location: ".str_replace("amp;","",treatGet(base64_decode($_GET['redir'])))); exit; } else { header("Location: ".$GLOBALS['rootRel']."index.php"); exit; } } } elseif(eregi("step1",base64_decode($_GET['redir']))) { header("Location: ".$GLOBALS['rootRel']."cart.php?act=step1"); exit; } } $login = new XTemplate ("skins/".$config['skinDir']."/styleTemplates/content/login.tpl"); $login->assign("LANG_LOGIN_TITLE",$lang['front']['login']['login']); $login->assign("VAL_SELF",treatGet($_GET['redir'])); $login->assign("LANG_USERNAME",$lang['front']['login']['username']); if(isset($_POST['username'])){ $login->assign("VAL_USERNAME",$_POST['username']); } $login->assign("LANG_PASSWORD",$lang['front']['login']['password']); $login->assign("LANG_REMEMBER",$lang['front']['login']['remember_me']); $login->assign("TXT_LOGIN",$lang['front']['login']['login']); $login->assign("LANG_FORGOT_PASS",$lang['front']['login']['forgot_pass']); if(isset($_POST['remember']) && $_POST['remember']==1) $login->assign("CHECKBOX_STATUS","checked='checked'"); if($ccUserData[0]['customer_id'] > 0 && isset($_POST['submit'])){ $login->assign("LOGIN_STATUS",$lang['front']['login']['login_success']); } elseif($ccUserData[0]['customer_id'] > 0 && !isset($_POST['submit'])) { $login->assign("LOGIN_STATUS",$lang['front']['login']['already_logged_in']); } elseif($ccUserData[0]['customer_id'] == 0 && isset($_POST['submit'])) { if($blocked == TRUE) { $login->assign("LOGIN_STATUS",sprintf($lang['front']['login']['blocked'],sprintf("%.0f",$ini['bftime']/60))); } else { $login->assign("LOGIN_STATUS",$lang['front']['login']['login_failed']); } $login->parse("login.form"); } else { $login->assign("LOGIN_STATUS",$lang['front']['login']['login_below']); $login->parse("login.form"); } $login->parse("login"); $page_content = $login->text("login"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/52708-adding-a-browserupload-box-to-a-page/ 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.