Jump to content

ryanharper

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

ryanharper's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I moved this to the freelance forum... http://www.phpfreaks.com/forums/index.php?topic=338428.0
  2. i took it out as it was not working...
  3. i used the move_uploaded_file and upon upload got no errors but the file was not showing the directory. permissions were set correctly so I am confused...
  4. Hello all! I am working on a submission form at a website of my. I have it working except that I originally wrote the script to upload files into Mysql. I realized that his is not the method I need and am trying to change the script to upload the selected file into a directory and the link to this directory to go into mysql. Here is the upload.php code ____________________________________________________________________ <?php include 'dbc.php'; page_protect(); $table = 'upload'; // use the same name as SQL table $password = 'XXXXXX'; // simple upload restriction, // to disallow uploading to everyone // This function makes usage of // $_GET, $_POST, etc... variables // completly safe in SQL queries function sql_safe($s) { if (get_magic_quotes_gpc()) $s = stripslashes($s); return mysql_real_escape_string($s); } // If user pressed submit in one of the forms if ($_SERVER['REQUEST_METHOD'] == 'POST') { // cleaning title field $title = trim(sql_safe($_POST['title'])); $name = ($_POST['name']); $type = ($_POST['type']); $subject = ($_Post['subject']); if ($title == '') // if title is not set $msg = 'Error: enter username'; if ($name == '') // if name is not set $msg = 'Error: enter file name'; if ($type == '') // if name is not set $msg = 'Error: enter the file type'; if ($_POST['password'] != $password) // cheking passwors $msg = 'Error: wrong upload password'; else { if (!isset($msg)) // If there was no error { $data = file_get_contents($_FILES['photo']['tmp_name']); $data = mysql_real_escape_string($data); // Preparing data to be used in MySQL query mysql_query("INSERT INTO {$table} SET type='$type', subject='$subject' , name='$name', title='$title', data='$data'"); $msg = 'Success: file uploaded'; } elseif (isset($_GET['title'])) // isset(..title) needed $msg = 'Error: file not loaded';// to make sure we've using // upload form, not form // for deletion if (isset($_POST['del'])) // If used selected some photo to delete { // in 'uploaded images form'; $id = intval($_POST['del']); mysql_query("DELETE FROM {$table} WHERE id=$id"); $msg = 'Photo deleted'; } } } elseif (isset($_GET['show'])) { $id = intval($_GET['show']); $result = mysql_query("SELECT ext, image_time, data FROM {$table} WHERE id=$id LIMIT 1"); if (mysql_num_rows($result) == 0) die('no image'); list($ext, $image_time, $data) = mysql_fetch_row($result); $send_304 = false; if (php_sapi_name() == 'apache') { // if our web server is apache // we get check HTTP // If-Modified-Since header // and do not send image // if there is a cached version $ar = apache_request_headers(); if (isset($ar['If-Modified-Since']) && // If-Modified-Since should exists ($ar['If-Modified-Since'] != '') && // not empty (strtotime($ar['If-Modified-Since']) >= $image_time)) // and grater than $send_304 = true; // image_time } if ($send_304) { // Sending 304 response to browser // "Browser, your cached version of image is OK // we're not sending anything new to you" header('Last-Modified: '.gmdate('D, d M Y H:i:s', $ts).' GMT', true, 304); exit(); // bye-bye } // outputing Last-Modified header header('Last-Modified: '.gmdate('D, d M Y H:i:s', $image_time).' GMT', true, 200); // Set expiration time +1 year // We do not have any photo re-uploading // so, browser may cache this photo for quite a long time header('Expires: '.gmdate('D, d M Y H:i:s', $image_time + 86400*365).' GMT', true, 200); // outputing HTTP headers header('Content-Length: '.strlen($data)); header("Content-type: image/{$type}"); // outputing image echo $data; exit(); } ?> <?php include("upheader.html"); ?> <?php if (isset($msg)) // this is special section for // outputing message { ?> <p style="font-weight: bold;"><?=$msg?> <br> <a href="<?=$PHP_SELF?>">reload page</a> <!-- I've added reloading link, because refreshing POST queries is not good idea --> </p> <?php } ?> </form> <h2>Upload new file:</h2> <form action="<?=$PHP_SELF?>" method="POST" enctype="multipart/form-data"> <label for="title">Username:</label><br> <input type="text" name="title" id="title" size="64"><br><br> <label for="subject">Subject:</label><br> <select name="subject" class="required" id="select8"> <option value="" selected></option> <option value="acct">Accounting</option> <option value="anth">Anthropology</option> <option value="bio">Biology</option> <option value="chem">Chemistry</option> <option value="comm">Communications</option> <option value="econ">Economics</option> <option value="engl">English</option> <option value="fmgt">Finance</option> <option value="geog">Geography</option> <option value="grph">Graphic Design</option><br> <option value="hum">Humanities</option> <option value="cit">Information Technology</option> <option value="mkgt">Marketing</option> <option value="phil">Philosophy</option> <option value="pols">Political Science</option> <option value="psy">Psychology</option> <option value="soc">Sociology</option> </select><br><br> <label for="name">File Name:</label><br> <input type="text" name="name" id="name" size="64"><br><br> <label for="type">File Type:</label><br> <select name="type" class="required" id="select8"> <option value="" selected></option> <option value="doc">.doc</option> <option value="docx">.docx</option> <option value="rtf">.rtf</option> <option value="xls">.xls</option> <option value="txt">.txt</option> <option value="pdf">.pdf</option> <option value="zip">.zip</option> </select><br><br> <label for="photo">Select File:</label><br> <input type="file" name="photo" id="photo"><br><br> <label for="password">Password:</label><br> <input type="password" name="password" id="password"><br><br> <input type="submit" value="upload"> </form> <?php include("footer.html"); ?> _______________________________________________________ the database is: Field Type Collation Attributes Null Default Extra Action id int(11) No auto_increment title varchar(64) utf8_general_ci No subject varchar(40) utf8_general_ci No name varchar(60) utf8_general_ci No type varchar( utf8_general_ci No image_time on update current timestamp No data text utf8_general_ci No *id is primary PLEASE HELP!!! I have tried a few different options but cannot get the file to the directory or the link into the database. I think I have worked myself in circles at this point and need a fresh perspective... ANY thoughts or help is GREATLY appreciated!!! rh
  5. i wasn't sure where in the files i should put the mail function but after a few attempts i found it - thank you! RH
  6. i have a members table set up in MySQL. when someone registers at the site, their info goes to the table and they can not login until it has been approved. Is there a PHP script i can use that will send an email to the admin when a person submits registration form?
  7. I am using PHP-Login (http://phpsense.com/php/php-login-script.html)and need to manually approve users who register... Can someone help me add code to this in order to make it happen?
  8. Ignace, my login-exec.php page contains the following <?php //Start session session_start(); //Include database connection details require_once('config.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $login = clean($_POST['login']); $password = clean($_POST['password']); //Input Validations if($login == '') { $errmsg_arr[] = 'Login ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'Password missing'; $errflag = true; } //If there are input validations, redirect back to the login form if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: login-form.php"); exit(); } //Create query $qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'"; $result=mysql_query($qry); //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) == 1) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['member_id']; $_SESSION['SESS_FIRST_NAME'] = $member['firstname']; $_SESSION['SESS_LAST_NAME'] = $member['lastname']; session_write_close(); header("location: member-index.php"); exit(); }else { //Login failed header("location: login-failed.php"); exit(); } }else { die("Query failed"); } ?> where do I add the code you suggested to make this work?
  9. I have a site protected with PHP and SQL. Once registered you are automatically in the database and log in. Is there a way that I can have a user register and approve their account before they are able to login? Please Help!!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.