Jump to content

seanj43

Members
  • Posts

    14
  • Joined

  • Last visited

    Never

Everything posted by seanj43

  1. Ok, I feel I am so close to solving this... <?php $dir = "images/"; if ($opendir = opendir($dir) ) { while ( ($file = readdir($opendir) ) !== FALSE) { if ($file!="."&&$file!="..") echo "<img src = '$dir$file/FILENAME.jpg'"; } } ?> This returns an image at mysite.com/images/subdirectory/FILENAME.jpg How can I get it to automatically include the filename in the link? I have tried readdir(images/$file) but it doesn't work for some reason.
  2. Ok I seem to have found a way around this using this code: <?php $dir = "images/"; if ($opendir = opendir($dir) ) { while ( ($file = readdir($opendir) ) !== FALSE) { if ($file!="."&&$file!="..") echo "$file"; } } ?> This code returns a list of sub-directory names within the parent directory of 'images'. How could I then use this information to get the code to then read the sub-directories and output the filenames of the contents of the sub-directories? I figure I could use $file (sub-directory name), but how? I can't get my head around it.
  3. There is no error now, but the code doesn't appear to do anything. I'm probably missing something really obvious... <?php function getFiles($directory,$exempt = array('.images'),&$files = array()) { $handle = opendir($directory); while(false !== ($resource = readdir($handle))) { if(!in_array(strtolower($resource),$exempt)) { if(is_dir($directory.$resource.'/')) array_merge($files, self::getFiles($directory.$resource.'/',$exempt,$files)); else $files[] = $directory.$resource; } } closedir($handle); return $files; } ?>
  4. Hmm that doesn't seem to do anything apart from return an error.
  5. Thank you I have sorted this out now, but it has ruined another code I'm running. <?php $files = glob("images/*.*"); for ($i=0; $i<count($files); $i++) { $num = $files[$i]; echo '<img src="'.$num.'" alt="random image">'." "; } ?> I was using this code to display all images from the directory 'images', but now I am using multiple sub-directories within the parent directory 'images' to store my images. How can I change this code so it will display all images in the directory 'images' including the contents of all sub-directories?
  6. Thanks for that. How could I implement this into the code to be able to define a target directory? So it would display a list of existing directories on the upload page, and I could chose which one to upload the image to?
  7. I am using the following code: <?php $target = "images/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } ?> I am using this to upload photos to the directory called 'images'. How could I change this code so that I can choose an existing directory to upload it to and also create a new directory to upload it to if I wanted?
  8. Sorry stupid question. It worked. Thanks!
  9. Is there a way to reset a session? Here is my code... <?php session_start(); if (!isset($_SESSION['logged_in'])) { header("Location: login.php"); } mysql_connect("localhost", "user", "password")or die("cannot connect"); mysql_select_db("database")or die("cannot select DB"); $bio = $_POST['Bio']; $location = $_POST['Location']; $username = $_SESSION["user_name"]; $sql = "UPDATE users SET bio = '$bio', location = '$location' WHERE username = '$username'"; $result = mysql_query($sql) or die ("Error in query: $sql. " . mysql_error()); ?> Now I have a session called bio that I need to reset so that it will store the new bio information. How can I do this? I tried to unset the session and start it again but this didn't work.
  10. Here is my code... <?php mysql_connect("localhost", "user", "pass")or die("cannot connect"); mysql_select_db("database")or die("cannot select DB"); $myemail = mysql_real_escape_string($_POST['myemail']); $mypassword = mysql_real_escape_string($_POST['mypassword']); $mypassword = md5($mypassword); $myemail = stripslashes($myemail); $mypassword = stripslashes($mypassword); $sql="SELECT * FROM users WHERE email='$myemail' and password='$mypassword'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ session_start(); $_SESSION["myemail"]= "$myemail"; header("location:home.php"); } else { header("location:fail.php"); } ?> What can I do to this code so that it will also store first name from the database inside a session?
  11. So how and where should I implement this in my code?
  12. Well I have looked everywhere for a tutorial but I am unable to find one that works/I understand. Could anybody point me in the right direction? As for the code being old and not correct, I found it on a tutorial website. It works, but what does it need doing to it to make it 'correct'? EDIT: Update to code <?php mysql_connect("localhost", "user", "password")or die("cannot connect"); mysql_select_db("db name")or die("cannot select DB"); $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $mypassword=md5($mypassword); $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM users WHERE email='$myusername' and password='$mypassword'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ session_register("myusername"); session_register("mypassword"); header("location:success.php"); } else { header("location:fail.php"); } ?>
  13. Firstly, I am new to the forum, so hello I am trying to code a login script for my website. I have got the login to work but how do I get it to create a session so the user stays logged in until they log out? Also how can I prevent access to success.php and fail.php so they cannot be accessed directly. I am new to PHP so please explain in detail for me. Here is my code... <?php ob_start(); $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name=""; // Table name mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $mypassword=md5($mypassword); $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE email='$myusername' and password='$mypassword'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ session_register("myusername"); session_register("mypassword"); header("location:success.php"); } else { header("location:fail.php"); } ob_end_flush(); ?>
×
×
  • 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.