Jump to content

happypete

Members
  • Content Count

    124
  • Joined

  • Last visited

  • Days Won

    1

happypete last won the day on September 29 2012

happypete had the most liked content!

Community Reputation

16 Neutral

About happypete

  • Rank
    Advanced Member

Profile Information

  • Gender
    Male
  1. Try this. Create an index.php, ageCheck.php & verified.php page and use the code below. Navigate to the verified.php page in the browser first (to check its working) you should automatically be redirected to the index.php page. Now if you select "i'm 21" then you will be redirected to the verified page. index.php <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> </head> <body> <form method="POST" action="ageCheck.php"> <input type="submit" name="valid_age" value="I'm 21" /> <input type="submit" name="invalid_age" value="Nope. I sit at the kid's table" /> </form> </body> </html> When they select either of the button the details will be sent to the ageCheck.php page: ageCheck.php <?php //Start session session_start(); /* * First, we want to make sure they came to this ageCheck.php via a form. * Then we can check to see if $_POST['valid_age'] is set, since it will only * be set if they pressed the "I'm 21" button. */ if(isset($_POST)){ if(isset($_POST['valid_age'])){ /* * Since they got here, it means they are of the right age. * Now we set the session value. */ $_SESSION['age_verified'] = true; header("Location: verified.php"); exit; }else{ /* * To young! Just re-direct them to Google. */ header("Location: http://www.google.com"); exit; } }else{ die("Trying to sneak in are we?"); } ?> This page will send them to google.com if they have selected "Nope. I sit at the kid's table", or send them to verified.php if they selected "I'm 21" verified.php <?php //Start the session session_start(); /* * If they haven't passed the age test * then the age_verified session will not * be set, since it is only set if they * say they are 21 years of age. */ if(!isset($_SESSION['age_verified'])){ header("Location: index.php"); exit; } else { $verified = "your age has been verified!"; } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> </head> <body> <?php echo $verified; ?> </body> </html> On the verified page it will again check if they are verified (and send them to index.php if not) of will echo "your age has been verified!" Any other page that you want them to visit and check they have been verified their age, add this code at the top. If they are not verified it will send then back to the index.php page <?php //Start the session session_start(); /* * If they haven't passed the age test * then the age_verified session will not * be set, since it is only set if they * say they are 21 years of age. */ if(!isset($_SESSION['age_verified'])){ header("Location: index.php"); exit; } else { $verified = "your age has been verified!"; } ?>
  2. Awesome, thanks, that worked: window.addEventListener("change", function(e) { e.preventDefault(); e.stopPropagation(); upcontrol.start(e.target.files);
  3. I have an image upload script which works file on desktop but not on mobile so I am trying to change the drag drop file input to select multiple files. original: <!-- DROP ZONE --> <div id="uploader"> <div class="drop">Drop Files Here</div> </div> /* !! UPDATE : AJAX IS ASYNCHRONOUS !! */ /* We do not want users to dump 100 files & upload all at the same time */ /* This will create sort of a queue system & upload one at a time */ var upcontrol = { queue : null, // upload queue now : 0, // current file being uploaded start : function (files) { // upcontrol.start() : start upload queue // WILL ONLY START IF NO EXISTING UPLOAD QUEUE if (upcontrol.queue==null) { // VISUAL - DISABLE UPLOAD UNTIL DONE upcontrol.queue = files; document.getElementById('uploader').classList.add('disabled'); // PROCESS UPLOAD - ONE BY ONE upcontrol.run(); } }, run : function () { // upcontrol.run() : proceed upload file var xhr = new XMLHttpRequest(), data = new FormData(); data.append('file-upload', upcontrol.queue[upcontrol.now]); xhr.open('POST', 'process.php', true); xhr.onload = function (e) { // SHOW UPLOAD STATUS var fstat = document.createElement('div'), txt = upcontrol.queue[upcontrol.now].name + " - "; if (xhr.readyState === 4) { if (xhr.status === 200) { // SERVER RESPONSE txt += xhr.responseText; } else { // ERROR txt += xhr.statusText; } } fstat.innerHTML = txt; document.getElementById('upstat').appendChild(fstat); // UPLOAD NEXT FILE upcontrol.now++; if (upcontrol.now < upcontrol.queue.length) { upcontrol.run(); } // ALL DONE else { upcontrol.now = 0; upcontrol.queue = null; document.getElementById('uploader').classList.remove('disabled'); // callback text done! done.innerHTML = "Uploads Complete"; document.getElementById('done').appendChild(done); } }; xhr.send(data); } }; window.addEventListener("load", function () { // IF DRAG-DROP UPLOAD SUPPORTED if (window.File && window.FileReader && window.FileList && window.Blob) { /* [THE ELEMENTS] */ var uploader = document.getElementById('uploader'); /* [UPLOAD MECHANICS] */ // STOP THE DEFAULT BROWSER ACTION FROM OPENING THE FILE uploader.addEventListener("dragover", function (e) { e.preventDefault(); e.stopPropagation(); }); uploader.addEventListener("drop", function (e) { e.preventDefault(); e.stopPropagation(); uploader.classList.remove('highlight'); upcontrol.start(e.dataTransfer.files); }); New <input type="file" id="uploader" name="files[]" accept="image/jpeg, image/jpg, image/gif, image/png" multiple/> This bit the same as before /* !! UPDATE : AJAX IS ASYNCHRONOUS !! */ /* We do not want users to dump 100 files & upload all at the same time */ /* This will create sort of a queue system & upload one at a time */ var upcontrol = { queue : null, // upload queue now : 0, // current file being uploaded start : function (files) { // upcontrol.start() : start upload queue // WILL ONLY START IF NO EXISTING UPLOAD QUEUE if (upcontrol.queue==null) { // VISUAL - DISABLE UPLOAD UNTIL DONE upcontrol.queue = files; document.getElementById('uploader').classList.add('disabled'); // PROCESS UPLOAD - ONE BY ONE upcontrol.run(); } }, run : function () { // upcontrol.run() : proceed upload file var xhr = new XMLHttpRequest(), data = new FormData(); data.append('file-upload', upcontrol.queue[upcontrol.now]); xhr.open('POST', 'process.php', true); xhr.onload = function (e) { // SHOW UPLOAD STATUS var fstat = document.createElement('div'), txt = upcontrol.queue[upcontrol.now].name + " - "; if (xhr.readyState === 4) { if (xhr.status === 200) { // SERVER RESPONSE txt += xhr.responseText; } else { // ERROR txt += xhr.statusText; } } fstat.innerHTML = txt; document.getElementById('upstat').appendChild(fstat); // UPLOAD NEXT FILE upcontrol.now++; if (upcontrol.now < upcontrol.queue.length) { upcontrol.run(); } // ALL DONE else { upcontrol.now = 0; upcontrol.queue = null; document.getElementById('uploader').classList.remove('disabled'); // callback text done! done.innerHTML = "Uploads Complete"; document.getElementById('done').appendChild(done); } }; xhr.send(data); } }; And this is where I am stuck. I'm trying to convert the drop to a select multiple files so need to change the "dataTransfer.files;" window.addEventListener("change", function(e) { e.preventDefault(); e.stopPropagation(); ///I believe this bit below is what needs changing???? upcontrol.start(e.dataTransfer.files); I get this far, and the console give the following error: "Uncaught TypeError: Cannot read property 'files' of undefined"
  4. Awesome thanks, that's just want I needed to know.
  5. Hi, I have an drag and drop image upload script that will process multiple image uploads with PHP, the JS gives a notification of each file uploaded. I want to be able to give an "all files uploaded" notification at the end ... index.php <script src="upload.js"></script> </head> <body> <h2>Upload a new image.</h2> <!-- DROP ZONE --> <div id="uploader"> <div class="drop">Drop Files Here</div> </div> upload.js /* !! UPDATE : AJAX IS ASYNCHRONOUS !! */ /* We do not want users to dump 100 files & upload all at the same time */ /* This will create sort of a queue system & upload one at a time */ var upcontrol = { queue : null, // upload queue now : 0, // current file being uploaded start : function (files) { // upcontrol.start() : start upload queue // WILL ONLY START IF NO EXISTING UPLOAD QUEUE if (upcontrol.queue==null) { // VISUAL - DISABLE UPLOAD UNTIL DONE upcontrol.queue = files; document.getElementById('uploader').classList.add('disabled'); // PROCESS UPLOAD - ONE BY ONE upcontrol.run(); } }, run : function () { // upcontrol.run() : proceed upload file var xhr = new XMLHttpRequest(), data = new FormData(); data.append('file-upload', upcontrol.queue[upcontrol.now]); xhr.open('POST', 'process.php', true); xhr.onload = function (e) { // SHOW UPLOAD STATUS var fstat = document.createElement('div'), txt = upcontrol.queue[upcontrol.now].name + " - "; if (xhr.readyState === 4) { if (xhr.status === 200) { // SERVER RESPONSE txt += xhr.responseText; } else { // ERROR txt += xhr.statusText; } } fstat.innerHTML = txt; document.getElementById('upstat').appendChild(fstat); // UPLOAD NEXT FILE upcontrol.now++; if (upcontrol.now < upcontrol.queue.length) { upcontrol.run(); } // ALL DONE // // // I WANT TO ADD SOME CODE HERE TO CREATE A MESSAGE ON THE INDEX.PHP TO SAY ALL IMAGES UPLOADED // // // else { upcontrol.now = 0; upcontrol.queue = null; document.getElementById('uploader').classList.remove('disabled'); } }; xhr.send(data); } };
  6. Thanks for the comments, I will do some more research.
  7. Hi, I'm trying to edit some database fields, I have text1, text2, text3, text4, text5, text6 etc.. They are displayed on the index.php page, with an edit link so the user can choose which set to edit // Extract details from database $sql = "SELECT * FROM data WHERE id=1"; $stmt = $db->prepare($sql); $stmt->execute(); $e = $stmt->fetch(); <h1><?php echo $e['text1']) ?></h1> <p><?php echo ($e['text2']); ?></p> <p><a href="edit.php">EDIT</a></p> <h1><?php echo $e['text3']) ?></h1> <p><?php echo ($e['text4']); ?></p> <p><a href="edit.php">EDIT</a></p> <h1><?php echo $e['text5']) ?></h1> <p><?php echo ($e['text6']); ?></p> <p><a href="edit.php">EDIT</a></p> edit.php: // Extract details from database $sql = "SELECT * FROM data WHERE id=1"; $stmt = $db->prepare($sql); $stmt->execute(); $e = $stmt->fetch(); <form method="post" action="process.php" enctype="multipart/form-data"> <label>Page Title <input type="text" name="text1" maxlength="90" value="<?php echo $e['text1'] ?>" /> </label> <br> <label>Title Text</label> <textarea name="text2"><?php echo $e['text2'] ?></textarea> <input id="button" type="submit" name="submit" value="Save Changes" /> and then update them: process.php $sql = "UPDATE data SET text1=?, text2=? WHERE id=1 LIMIT 1"; $stmt = $db->prepare($sql); $stmt->execute( array( $_POST['text1'], $_POST['text2'] ) ); $stmt->closeCursor(); Question: How can I pass the form values dynamically from the index.php page so I don't have to hard code text1, text2 etc into the edit.php and process.php page and have a different update & process page for each set of data? Thanks in advance.
×
×
  • 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.