Jump to content

Html

Members
  • Posts

    640
  • Joined

  • Last visited

Everything posted by Html

  1. I searched on bing. <?php $fileList = glob('test/*'); foreach($fileList as $filename){ //Use the is_file function to make sure that it is not a directory. if(is_file($filename)){ echo $filename, '<br>'; } } https://thisinterestsme.com/php-list-all-files-in-a-directory/
  2. The set directory, being the upload_tmp one. So what about simply display images that have been sent to a folder in the directory, how can the images simply be displayed on a page, they'd simply be listed as a row going down, I am guessing without any CSS.
  3. Right, so the image is stored then in $temp, this value. upload_tmp_dir Directive /tmp So this is local value, /tmp And Master value
  4. Hi, Where does the image uploaded here in this, display once it has been uploaded to a directory <!DOCTYPE HTML> <html lang="en"> <head> <meta charset="UTF-8"> <title>PHP File Upload</title> </head> <body> <form method="POST" action="<?php $_SERVER[ 'PHP_SELF' ] ?>" enctype="multipart/form-data"> Select an image to upload : <input type="file" name="image" > <input type="submit" value="Upload Image" > </form> <?php if( $_SERVER[ 'REQUEST_METHOD' ] == 'POST' ) { $name = $_FILES[ 'image' ][ 'name' ] ; $temp = $_FILES[ 'image' ][ 'tmp_name' ] ; $size = $_FILES[ 'image' ][ 'size' ] ; $ext = pathinfo( $name , PATHINFO_EXTENSION ) ; $ext = strtolower( $ext ) ; if( $ext != 'png' && $ext != 'jpg' && $ext != 'gif' ) { echo 'Format must be PNG, JPG, or GIF' ; exit() ; } if( $size > 512000) { echo 'File size must not exceed 500Kb' ; exit() ; } if( file_exists( $name ) ) { echo 'File '.$name.' already uploaded' ; exit() ; } try { move_uploaded_file( $temp , $name ) ; echo 'File uploaded : '.$name ; echo '<br><img src="'.$name.'">' ; } catch( Exception $e ) { echo 'File upload failed!' ; } } ?> </body> </html> I have something a little similar, which was probably helped by a few on here last year. That works as is, but I'm curious to know where exactly, the image is temporarily displayed in this code. While this code is structured for uploading to the main directory, and not a specific folder, it does display the image. { move_uploaded_file( $temp , $name ) ; echo 'File uploaded : '.$name ; echo '<br><img src="'.$name.'">' ; } Could be this?
  5. So image needs to be changed a little?
  6. Hmm, the reason I began searching these examples is because I couldn't go further with just learning the language. I do have the SQL in easy steps book, but I don't it covers quite what I am doing. It is all to do with just editing in the actual sql db, not using it in php for web pages. That code alone has vulnerability? Where about is it, and it is easy to patch up?
  7. I'm going to need an example. 😕
  8. $sql = "SELECT FROM images WHERE user_id users.userid=$user_id AND images.userid =$user_id "; I think this is correct on the names.
  9. I remove the auto increment setting for images table. So, this sql statement will fit into this code. This below is wrong, $sql = "SELECT FROM images WHERE user_id images.userid=$user_id AND imagetablename.userid =$user_id "; <?php while ($row = msql_fetch_array($result, MSQL_ASSOC)) echo "<div id='img_div'>"; echo ".$row['user_id']."'"; echo "<img src='images/".$row['image']."' >";  echo "<p>".$row['image_text']."'</p>";  echo "</div>"; } ?> 
  10. CREATE TABLE IF NOT EXISTS images ( user_id INT UNSIGNED NOT NULL AUTO_INCREMENT, image VARCHAR(100) NOT NULL, image_text text NOT NULL, reg_date DATETIME NOT NULL, PRIMARY KEY (user_id) ); I decided to create the table this way, so user_id is consistent. The other way I couldn't really get it edited, and working. So may be this is a little better. As for values, what exactly, this is the image table, and the user table is obviously different, in values, so I don't quite understand what you mean by adding the same values, only user_id is currently the same in both tables now. As well reg_date, not that important, I guess?
  11. Instead of id, user_id? Keep both. echo ".$row['user_id']."'"; This alone will link them? it will connect with it. I am going to need to type some code for this? , 'you retrieve user table and image table together where user_id equals userid or user_id? from the image table '
  12. Well, are you getting at they must be linked somehow, here is an image, I'm not giving enough info on what I have. All I did was do what the page has stated.
  13. <?php while ($row = msql_fetch_array($result, MSQL_ASSOC)) echo "<div id='img_div'>"; echo ".$row['user_id']."'"; echo "<img src='images/".$row['image']."' >";  echo "<p>".$row['image_text']."'</p>";  echo "</div>"; } ?>  There is only id for the images table, so user_id won't work like I have placed it above? Since user_id is on the users table.
  14. <?php while ($row = msql_fetch_array($result, MSQL_ASSOC)) echo "<div id='img_div'>"; echo "<img src='images/".$row['image']."' >";  echo "<p>".$row['image_text']."'</p>";  echo "</div>"; } ?>  Keep it like this, I thought the example was necessary for an id add in.
  15. I tried this code or another, but it didn't work. The user site I use, it uses Sha2. I tried removing it, it only breaks the system, so how to use it with this, I am not sure about that. Change pass is something I am not that concerned about, especially if the code is rubbish as you've pointed out. Remove data was important, i got some code help elsewhere for that. Now that image id task.
  16. So add image and image_text to the users table? Hmm, as for the id, how does that work out with the code above? <?php while ($_Session, $row = mysqli_fetch_array($result)) { echo "<div id='img_div'>"; echo "<img src='images/".$row['image']."' >"; echo "<p>".$row['image_text']."</p>"; echo "</div>"; } ?> while ($row = msql_fetch_array($result, MSQL_ASSOC)) { echo $row['id'] . ': ' . $row['name'] . "\n"; Is this above required for the code from the image code? <?php while ($row = msql_fetch_array($result, MSQL_ASSOC)) { echo $row['id'] . ': ' . $row['image'] : ' . $row['image_text'] . "\n"; echo "<div id='img_div'>"; echo "<img src='images/".$row['image']."' >"; echo "<p>".$row['image_text']."</p>"; echo "</div>"; } ?>
  17. Yes, not sure where, I tried the obvious above for the display of the image, but that won't work in the php code checker. Currently it just uploads an image, stores in the db, and displays on the same page as the code displays. So for it to be a particular user, session id is required especially for the display code. I did try it, but it didn't work, that is without the $_session. <?php while ($_Session, $row = mysqli_fetch_array($result)) { echo "<div id='img_div'>"; echo "<img src='images/".$row['image']."' >"; echo "<p>".$row['image_text']."</p>"; echo "</div>"; } ?> $result = mysqli_query($dbc, "SELECT * FROM images"); This below is where the display begins. https://www.php.net/manual/en/function.msql-fetch-array.php while ($row = msql_fetch_array($result, MSQL_ASSOC)) { echo $row['id'] . ': ' . $row['name'] . "\n";
  18. <?php # Access session. session_start() ; # Redirect if not logged in. if ( !isset( $_SESSION[ 'user_id' ] ) ) { require ( 'login_tools.php' ) ; load() ; } // Create database connection $dbc = mysqli_connect("", "", "", ""); // Initialize message variable $msg = ""; // If upload button is clicked ... if (isset($_POST['upload'])) { // Get image name $image = $_FILES['image']['name']; // Get text $image_text = mysqli_real_escape_string($db, $_POST['image_text']); // image file directory $target = "images/".basename($image); $sql = "INSERT INTO images (image, image_text) VALUES ('$image', '$image_text')"; // execute query mysqli_query($dbc, $sql); if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) { $msg = "Image uploaded successfully"; }else{ $msg = "Failed to upload image"; } } $result = mysqli_query($dbc, "SELECT * FROM images"); ?> <!DOCTYPE html> <html> <head> <title>Image Upload</title> <style type="text/css"> #content{ width: 50%; margin: 20px auto; border: 1px solid #cbcbcb; } form{ width: 50%; margin: 20px auto; } form div{ margin-top: 5px; } #img_div{ width: 80%; padding: 5px; margin: 15px auto; border: 1px solid #cbcbcb; } #img_div:after{ content: ""; display: block; clear: both; } img{ float: left; margin: 5px; width: 300px; height: 140px; } </style> </head> <body> <div id="content"> <?php while ($row = mysqli_fetch_array($result)) { echo "<div id='img_div'>"; echo "<img src='images/".$row['image']."' >"; echo "<p>".$row['image_text']."</p>"; echo "</div>"; } ?> <form method="POST" action="upload.php" enctype="multipart/form-data"> <input type="hidden" name="size" value="1000000"> <div> <input type="file" name="image"> </div> <div> <button type="submit" name="upload">POST</button> </div> </form> </div> </body> </html> I got this upload an image code from here, I have tinkered it so it works, I just need to get it be personal for a user, and display the uploaded image at a particular page. https://codewithawa.com/posts/image-upload-using-php-and-mysql-database <?php while ($_Session, $row = mysqli_fetch_array($result)) { echo "<div id='img_div'>"; echo "<img src='images/".$row['image']."' >"; echo "<p>".$row['image_text']."</p>"; echo "</div>"; } ?> $_SESSION[ 'user_id' ] This particular code I want to display on the home.php page. I need to tuck in a $_session Thanks.
  19. Hey there, So I checked out this code, is this okay to use? Obviously, the php code, I am looking at here. For the db, a new column, I guess in users table, would be needed a password and as varchar 20. `password` varchar(55) NOT NULL, <?php session_start(); $_SESSION["userId"] = "1"; $conn = mysqli_connect("localhost", "root", "test", "blog_samples") or die("Connection Error: " . mysqli_error($conn)); if (count($_POST) > 0) { $result = mysqli_query($conn, "SELECT *from users WHERE userId='" . $_SESSION["userId"] . "'"); $row = mysqli_fetch_array($result); if ($_POST["currentPassword"] == $row["password"]) { mysqli_query($conn, "UPDATE users set password='" . $_POST["newPassword"] . "' WHERE userId='" . $_SESSION["userId"] . "'"); $message = "Password Changed"; } else $message = "Current Password is not correct"; } ?> <html> <head> <title>Change Password</title> <link rel="stylesheet" type="text/css" href="styles.css" /> <script> function validatePassword() { var currentPassword,newPassword,confirmPassword,output = true; currentPassword = document.frmChange.currentPassword; newPassword = document.frmChange.newPassword; confirmPassword = document.frmChange.confirmPassword; if(!currentPassword.value) { currentPassword.focus(); document.getElementById("currentPassword").innerHTML = "required"; output = false; } else if(!newPassword.value) { newPassword.focus(); document.getElementById("newPassword").innerHTML = "required"; output = false; } else if(!confirmPassword.value) { confirmPassword.focus(); document.getElementById("confirmPassword").innerHTML = "required"; output = false; } if(newPassword.value != confirmPassword.value) { newPassword.value=""; confirmPassword.value=""; newPassword.focus(); document.getElementById("confirmPassword").innerHTML = "not same"; output = false; } return output; } </script> </head> <body> <form name="frmChange" method="post" action="" onSubmit="return validatePassword()"> <div style="width: 500px;"> <div class="message"><?php if(isset($message)) { echo $message; } ?></div> <table border="0" cellpadding="10" cellspacing="0" width="500" align="center" class="tblSaveForm"> <tr class="tableheader"> <td colspan="2">Change Password</td> </tr> <tr> <td width="40%"><label>Current Password</label></td> <td width="60%"><input type="password" name="currentPassword" class="txtField" /><span id="currentPassword" class="required"></span></td> </tr> <tr> <td><label>New Password</label></td> <td><input type="password" name="newPassword" class="txtField" /><span id="newPassword" class="required"></span></td> </tr> <td><label>Confirm Password</label></td> <td><input type="password" name="confirmPassword" class="txtField" /><span id="confirmPassword" class="required"></span></td> </tr> <tr> <td colspan="2"><input type="submit" name="submit" value="Submit" class="btnSubmit"></td> </tr> </table> </div> </form> </body> </html> https://phppot.com/php/php-change-password-script/
  20. A $_session is going to be needed to know a particular id in the database row. How does that work with a function code? I had tried example code via a php site weeks ago which worked to solve my problem. I should of tried that. session_start() ; if ( !isset( $_SESSION[ 'user_id' ] ) ) { require ( 'login_tools.php' ) ; load() ; } # Access session. session_start(); $_SESSION[ 'user_id' ] = $data[ 'user_id' ] ; A few snippets of code taken from the two files of the example files. I am guessing the example I tinkered with doesn't have a system to remember who is logged or belongs to a user id. These sentences below are from the sessions tutorial on the site.
  21. And that example of the delete user, that is only for a specific name. How would I know exactly how to remove a user that is id 4, or 5? Based on that example? Get id, I tried this before for the image upload, the first example. The second example looks like it could work since I have user_id and not id # Get passed product id and assign it to a variable. if ( isset( $_GET['id'] ) ) $id = $_GET['id'] ; # Get passed product id and assign it to a variable. if ( isset( $_GET['user_id'] ) ) $user_id = $_GET['user_id'] ;
  22. For the moment, i am just going to keep going on with this with the example files. I think I'll need to start from the beginning for php 7. But I will have a difficult time with this, I don't think just going to start I will somehow get the hang of this, of where exactly would you be suggesting? I want a change password feature and display only the logged in user's posted message forum.php will be a profile index. Of course that will need to be changed to remove only a logged in user's permission to view it, as it would need to be a public page forum.php?=1 or what ever it will look like.
  23. I didn't do with with maths and language, when I was in education. I think I mentioned this before in a previous topic. So there is a repeating pattern. There have been many people who have tried php and mysql, and never got far with it. I have managed to stick with it, even though I am all over the place with this.
  24. I thought you'd eventually see what I am seeing, you are partly correct, I chase after specific examples to get what I need, I can't go from A-Z. Sure I found a few examples on different sites on sunday, and I tinkered with it. And it worked, if I had done this six months ago, I wouldn't of been here, at least not yet.🙄
  25. DELETE FROM Customers WHERE CustomerName='Alfreds Futterkiste'; This? That isn't an id as such, id would be like 2, 3.
×
×
  • Create New...