PHP - Simple Gallery Script, Not Working
well I lowered my standards massively. LOL. I decided to google, "php upload and display image", instead of "php gallery".
Here is the error I get Warning: copy(/images/sheila.jpg) [function.copy]: failed to open stream: No such file or directory in /hermes/bosweb/web173/b1739/sl.brendansite1/public_html/ealike2/smallgallery/smallgallery.php on line 59 and here is the script that I mostly understand. I thought it was the ..images/, but now I don't know what it is. any help greatly appreciated. thank you. below is the code for the page. Code: [Select] <!-- Start PHP Code For Image Upload --> <?php //define a maxim size for the uploaded images in Kb define ("MAX_SIZE","5060"); //This function reads the extension of the file. It is used to determine if the file is an image by checking the extension. function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } //This variable is used as a flag. The value is initialized with 0 (meaning no error found) //and it will be changed to 1 if an errro occures. //If the error occures the file will not be uploaded. $errors=0; //checks if the form has been submitted if(isset($_POST['Submit'])) { //reads the name of the file the user submitted for uploading $image=$_FILES['image']['name']; //if it is not empty if ($image) { //get the original name of the file from the clients machine $filename = stripslashes($_FILES['image']['name']); //get the extension of the file in a lower case format $extension = getExtension($filename); $extension = strtolower($extension); //if it is not a known extension, we will suppose it is an error and will not upload the file, //otherwise we will do more tests if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { //print error message echo '<h2>Unknown extension!</h2>'; $errors=1; } else { //get the size of the image in bytes //$_FILES['image']['tmp_name'] is the temporary filename of the file //in which the uploaded file was stored on the server $size=filesize($_FILES['image']['tmp_name']); //compare the size with the maxim size we defined and print error if bigger if ($size > MAX_SIZE*1024) { echo '<h2>You have exceeded the file size limit! Please reduce the image size to 100 Kb or less!</h2>'; $errors=1; } //we will give an unique name, for example the time in unix time format $image_name=$filename; //the new name will be containing the full path where will be stored (images folder) $newname="../images/".$image_name; //we verify if the image has been uploaded, and print error instead $copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied) { echo '<h2>Copy unsuccessful!</h2>'; $errors=1; }}}} //If no errors registred, print the success message if(isset($_POST['Submit']) && !$errors) { echo "<h2>File Uploaded Successfully!</h2><br />"; echo "<img src='http://ealike.com/images/<?php echo $image_name; ?> />"; } ?> <!-- End PHP Code For Image Upload --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <!-- Start Image Upload Form --> <form name="newad" method="post" enctype="multipart/form-data" action=""> <input type="file" name="image"> <input name="Submit" type="submit" value="Upload image"> </form> <!-- End Image Upload Form --> </body> </html> Similar TutorialsI have a form on my website which actions login.php. The login.php code is below: <?php include('includes/classes.php.inc'); session_start(); $link = new BaseClass(); $data = $link->query("SELECT * FROM logins"); $pass_accepted = false; if($_REQUEST['username'] && $_REQUEST['password']){ $username = $_REQUEST['username']; $password = $_REQUEST['password']; while($row = mysql_fetch_array($data)){ if(($row['username']==$useranme)&&($row['password']==$password){ echo 'Password correct!'; $_SESSION['loggedin']=true; $pass_accepted = true; } } } else { echo 'You did not enter a username or password!'; } if(!$pass_accepted){ echo 'Your password is incorrect'; } echo '<br>Please <a href="index.php">click here</a> to return to page'; ?> I have checked that my references are all correct however even when I enter the correct password it returns saying the password is incorrect. Any idea on why this could be? I am happy to answer any follow up questions. Regards Hello. i am writing an API for lua... that sends POST requests to a php script. this php script is malfunctioning. below is the code and error. The code.... very simple: $punc_body = explode(". ", $body); foreach ($punc_body as $k => $v) { $v = ucfirst($v); echo $v . "<br>"; // this is only here for testing purposes. } $body = implode(". ", $punc_body); Why doesn't this work? I threw in the echo $v in which it shows that it is doing everything properly, however when I implode the array everything that was capitalized is reverted back to lower-case. Can someone tell me whats wrong or what I'm missing here please. The code below works well and shows all the images in a folder in reverse chronological order. But I want to limit it to a certain number of images . This would enable me to have several pages of images. So the first page would display the latest 50 images, the second page would show 50-100, and the third, 100-150. Any helps on how to modify? I can create the pages manually. I just want to know how to limit the current page to a certain range. Code: [Select] <?php //Your folder $files = glob("images/*.*"); function sortnewestfilesfirst($a, $b) { return filemtime($b) - filemtime($a); } usort($files, "sortnewestfilesfirst"); $colCnt=0; echo '<table border="0" style="width:1000px;">'; for ($i=0; $i<count($files); $i++) { $colCnt++; if ($colCnt==1) echo '<tr>'; echo '<td width="20%" style="font-size:8.5px; font-family:arial">'; $num = $files[$i]; echo ' <div class="ImgBorder"> <div class="clipout"> <div class="clipin"> <a href="' . $num . '" rel="lightbox[all]"><img class="thumb ImgBorder" src="'.$num.'"> </a> </div> </div></div>'." "; echo '</td>'; if ($colCnt==6) { echo '</tr>'; $colCnt=0; } } echo '</table>'; ?> Hi all, i've set this script for my gallery, it works, it display me the name of the albums, but when i click to see the pictures inside, the page is blank, and also don't appear the "Back to the albums" link, i can't find the error in the code... Code: [Select] <html> <head> <script type="text/javascript" src="../lightbox2.05/js/lightbox.js"> </script> </head> <body> <?php $page = $_SERVER['PHP_SELF']; //settings $column = 5; //directories $base = "carrelli_noleggio"; $thumbs = "thumbs"; // get album $get_album = $_GET['album']; //if no album selected if (!$get_album) { echo "<b>Select an album:</b><p />"; //find each album and display as links $handle = opendir($base); while (($file = readdir($handle))!==FALSE) { if (is_dir($base."/".$file) && $file != "." && $file != ".." && $file != $thumbs) { echo "<a href='$page?album=$file'>$file</a><br />"; } } closedir($handle); } else { //check if album exist, and additional security checks if (!is_dir($base."/".$get_album) || strstr($get_album,".") !=NULL || strstr($get_album,"/") !=NULL || strstr($get_album,"\") !=NULL) { echo "Album doesn't exist."; } else { $x = 0; echo "<b>$get_album</b><p />"; $handle = opendir($base."/".$get_album); while (($file = readdir($handle)) !== FALSE) { if ($file != "." && $file != "..") { echo "<table style='display:inline;'><tr><td><a href='$base/$get_album/$files' ref='lightbox'<img src='$base/$thumbs/$file' height='100' width'100'></a></td></tr></table>"; $x++; if ($x==$column) { echo"<br />"; $x = 0; } } } closedir($handle); echo "<p /><a href='$page>Back to albums</a>"; } } ?> </body> </html> I have a very simple piece of code to create a grid based gallery. The thumbnails are loaded from a single directory and are name 1.jpg... 2.jpg... 3.jpg etc At the moment the images appear to be loaded in randomly. I want them to load in numerically in terms of their filename. I know I may need to use 'sort' or 'natsort' but where in the code? Thanks for any help you can give me Code: [Select] <? $images = "Images/Bag Thumbs/"; # Location of small versions $big = "ruxxwomens.php?id="; # Location of big versions (assumed to be a subdir of above) $cols = 4; # Number of columns to display if ($handle = opendir($images)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && $file != rtrim($big,"/")) { $files[] = $file; } } closedir($handle); } $colCtr = 0; echo '<table width="800" cellspacing="0" cellpadding="0" border="0"><tr>'; foreach($files as $file) { if($colCtr %$cols == 0) echo '</tr><tr>'; echo '<td align="center"><a href="' . $big . $file . '"><img src="' . $images . $file . '" cellspacing="0" cellpadding="0" border="0"></a></td>'; $colCtr++; } echo '</table>' . "\r\n"; ?> I'm tired and just about given up. Can anybody help me? Code: [Select] <?php $objConnect = mysql_connect("localhost","","root") or die(mysql_error()); $objDB = mysql_select_db("sdf"); $pic2 = "SELECT * FROM images"; if (!isset($_GET['Page'])) $_GET['Page']='0'; $pic1 = mysql_query($pic2); $Num_Rows = mysql_num_rows($pic1); $Per_Page = 16; // Per Page $Page = $_GET["Page"]; if(!$_GET["Page"]) {$Page=1;} $Prev_Page = $Page-1; $Next_Page = $Page+1; $Page_Start = (($Per_Page*$Page)-$Per_Page); if($Num_Rows<=$Per_Page) {$Num_Pages =1;} else if(($Num_Rows % $Per_Page)==0) {$Num_Pages =($Num_Rows/$Per_Page) ;} else {$Num_Pages =($Num_Rows/$Per_Page)+1; $Num_Pages = (int)$Num_Pages;} $pic2 .=" order by thumbnailID ASC LIMIT $Page_Start , $Per_Page"; $pic1 = mysql_query($pic2); $cell = 0; $link1 = "SELECT * FROM images"; $result_link1 = mysql_query($link1); $link = mysql_fetch_array($result_link1); $alt1 = "SELECT * FROM images"; $alt = mysql_fetch_array(mysql_query($alt1)); echo ' <div id="tablediv"> <table border="0" cellpadding="17" cellspacing="0" class="table"> <tr>'; while($pic = mysql_fetch_array($pic1)) { if($cell % 4 == 0) { echo '</tr><tr>'; } if($cell == 2) { echo ' <td> fillerspace </td>'; } elseif ($cell == 3) { echo ' <td> Fillerspace2 </td>'; } else { echo ' <td> <a href="/' . $link["link"] . '.php"> <div class="image"> <img src="https://s3.amazonaws.com/image/' . $pic["pic"] . '.png" alt="' . $alt["alt"] . '" height="200" width="200" /> </div> </a> </td>'; } $cell++; } echo '</tr></table></div>'; ?> Basically, there are a couple of faults with this code. I didn't include the pagination part, but there is, for simplicity. But right now, when I insert a new record such as this: INSERT INTO `images` VALUES (' ', 'blog', 'yo', '6', 'hello', '2011-02-15T07:24:17Z') The columns go in order of thumbnailID, folder, link, pic, alt, and time.^^^^^^^^ several problem arises. One, the new record is not displayed as the newest entry on my site. So the record is actually placed in one of the paginated pages. How can I reverse the order? The other thing is, it seems like my pic column is the only thing being understood. You see, when I inserted the above record, I checked my site and saw the pic 6, but the link wasn't 'yo', and the alt wasn't 'hello'. Why is that? By the way, my host is awfully terrible. Maybe it's just having a major delay in reading the link and alt? I don't know. That would be the only reasonable answer, unless my code is off. Thank you, and I'll check 10hours from now. This topic has teleported to Third Party PHP Scripts. Beam me up, Scotty. http://www.phpfreaks.com/forums/index.php?topic=343682.0 Hello, im very green to php and I am having trouble creating a simple log in script. Not sure why this is not working, maybe a mysql_query mistake? I am not receiving any errors but nothing gets updated in the members table and my error message to the user displays. any help is appreciated! here is my php: <?php session_start(); $errorMsg = ''; $email = ''; $pass = ''; if (isset($_POST['email'])) { $email = ($_POST['email']); $pass = ($_POST['password']); $email = stripslashes($email); $pass = stripslashes($pass); $email = strip_tags($email); $pass = strip_tags($pass); if ((!$email) || (!$pass)) { $errorMsg = '<font color="#FF0000">Please fill in both fields</font>'; }else { include 'scripts/connect_db.php'; $email = mysql_real_escape_string ($email); $pass = md5($pass); $sql = mysql_query("SELECT * FROM members WHERE email='$email' AND password='$pass'"); $log_check = mysql_num_rows($sql); if ($log_check > 0) { while($row = mysql_fetch_array($sql)) { $id = $row["id"]; $_SESSION['id']; $email = $row["email"]; $_SESSION['email']; $username = $row["username"]; $_session['username']; mysql_query("UPDATE members SET last_logged=now() WHERE id='$id' LIMIT 1"); }//Close while loop echo "You are logged in"; exit(); } else { $errorMsg = '<font color="#FF0000">Incorrect login data, please try again</font>'; } } } ?> and the form: <?php echo $errorMsg; ?> <form action="log_in.php" method="post"> Email:<br /> <input name="email" type="text" /><br /><br /> Password:<br /> <input name="password" type="password" /><br /><br /> <input name="myBtn" type="submit" value="Log In" /> </form> Hi can someone pls help, im tryin a tutorial but keep getting errors, this is the first one i get after registering. You Are Registered And Can Now Login Warning: Cannot modify header information - headers already sent by (output started at /home/aretheyh/public_html/nealeweb.com/regcheck.php:43) in /home/aretheyh/public_html/nealeweb.com/regcheck.php on line 46 <html> <head></head> <body> My favourite bands a <ul> <?php // define arrays $morebands = array('Desturbed', 'Anthrax'); $artists = array('Metallica', 'Evanescence', 'Linkin Park', 'Guns n Roses', "$morebands"); // loop over it // print array elements foreach ($artists as $a) { if ($a != 'Array'){ echo '<li>'.$a; } Else { foreach ("${$a}" as $b){ echo '<li>'.$b; } } } ?> </ul> </body> </html> I can not figure out why this will not work:( I would like the foreach to run through the array as normal, but if it encounters a nested array, loop it as well. I know this likely is not the right, or best way to do this, but I am just learning PHP through a tutorial and I learn best by doing... So I take the lessons, make them more complicated, then figure out how to make it happen (like so). right now I am working on http://devzone.zend.com/node/view/id/635 anyhow thanks for any help! The following mysql query is not returning rows like I expect it to. '$update_field' is a variable, matching an actual field name in table 'users'. 'user_task[1]' is an integer value. What am I missing here? Code: [Select] $query_update_user = "UPDATE users SET ".$update_field." = 'Y' WHERE user_no = '".$user_task[1]."'"; I am running PHP Version 5.3.1. The following Code does not write to my database. It is code that I took from the PHP Pocket Reference from O'Reilly but it does not work... What's wrong with this code? Thanks in advance. Guy <?php if($vote && !$already_voted) SetCookie('already_voted',1); ?> <html> <head> <title>Name the Baby</title> </head> <h3>Name the Baby</h3> <form action="baby.php" method="POST"> <p>Suggestion: <input type="text" name="new_name"/> </p> <input type="submit" value="Submit idea and/or vote"/> <?php mysql_pconnect("localhost","root","password"); $db = "babynames"; $table = "baby_names"; if($new_name) { if(!mysql_db_query($db, "insert into $table values ('$new_name',0)")) { echo mysql_errno().': '. mysql_error()."<br />\n"; } } if($vote && $already_voted) { echo '<p><b>Hey, you voted already '; echo "Vote ignored.</b></p>\n"; } else if($vote) { if(!mysql_db_query($db, "update $table set votes=votes+1 where name='$vote'")) { echo mysql_errno().': '. mysql_error()."<br />\n"; } } $result=mysql_db_query($db,"select sum(votes) as sum from $table"); if($result) { $sum = (int) mysql_result($result,0,"sum"); mysql_free_result($result); } $result=mysql_db_query($db, "select * from $table order by votes DESC"); echo <<<EOD <table border="0"><tr><th>Vote</th> <th>Idea</th><th colspan="2">Votes</th></tr> EOD; while($row=mysql_fetch_row($result)) { echo <<<FOO <tr><td align="center"> <input type="radio" name="vote" value="$row[0]"></td> <td>$row[0]</td> <td align="right">$row[1]</td> <td> FOO; if ($sum && (int)$row[1]) { $per = (int)(100 * $row[1]/$sum); echo '<img src="bline.gif" height=12 '; echo "width=$per> $per %</td>"; } echo "</tr>\n"; } echo "</table>\n"; mysql_free_result($result); ?> <input type="submit" value="Submit idea and/or vote" /> <input type="reset" /> </form> </body></html> Hi, I am new to php, and I have run into a problem. The tutorial I am using has provided me with this exact code. But it does not work for me. Its very simple. Here is the HTML page: Code: [Select] <body> <FORM ACTION="welcome.php" METHOD=POST> First Name: <INPUT TYPE=TEXT NAME="name"> <INPUT TYPE=SUBMIT VALUE="GO"> </FORM> </body> And here is the php page: <body> <?php echo( "Welcome to our Web site, $name!" ); ?> </body> You can see the problem live at <http://www.freewaycreative.com/test> (dont mind the digits below) The name just does not show. Anyone know why? Thanks! Hey all,
This code was given to me by my client who swears it works, yet I can't seem to get it to function. <?php $now = time(); // or your date as well $your_date = strtotime("2016-06-01"); $datediff = $now - $your_date; $referrals = number_format(162250 + (floor($datediff/(60*60*24)) * 527) + (87920 + (floor($datediff/(60*60*24)) * 45))); ?> //javascript: <script> //vars from template var referrals = "<?php echo $referrals;?>"; var currentdate = new Date(); jQuery("document").ready(function() { jQuery ("#sp-menu > div > nav > ul > li:nth-child(1) > a").html("Home"); jQuery(".referrals").html(referrals); jQuery(".current_date").html((currentdate.getMonth()+1) + "/" + currentdate.getDate() + "/" + currentdate.getFullYear()); jQuery(window).on("scroll", function() { var scrollPos = jQuery(window).scrollTop(); if (scrollPos <= 0) { jQuery(".counter").fadeIn(); jQuery(".sec-nav").fadeIn(); } else { jQuery(".counter").fadeOut(); jQuery(".sec-nav").fadeOut(); } }); }); </script>
I'm trying my first PHP code :
<!DOCTYPE html>
<?php
</body>
Result : nothing, just a blank screen ... Am I missing something ?
Regards, Martin Hi, I have a php form that I use to try to get matching data from the database that I put into the form. So if I enter date of birth 9-4-80 and first name Dave and lastname Smith. When I submit it the code should pull all of the matching terms out of the database and display. Now I get the following error when I submit the form. Query: Resource id #2 Failed with error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #2' at line 1 any help Greatly appreciated. thank you! here is the code Code: [Select] <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); $host = " "; $database = " "; $username = " "; $password = " "; $tbl_name = "users"; $conn = mysql_connect($host, $username, $password) or die("Could not connect: " . mysql_error()); if($conn) { mysql_select_db($database); echo "connected to database!!"; } else { echo "failed to select database"; } //include('bouncer.php'); //$currentUser = $_SESSION['myusername']; if(isset($_POST['submit'])) { $first = mysql_real_escape_string( $_POST['first']); $last = mysql_real_escape_string( $_POST['last']); $dob = mysql_real_escape_string( $_POST['dob']); //THE SEARCH FUNCTION $sql = mysql_query ( "SELECT * FROM users WHERE firstname LIKE '%$first%' OR lastname LIKE '%$last%' OR dob LIKE '%$dob%' ") or die(mysql_error()); $result = mysql_query($sql) or die( "<br>Query: $sql<br>Failed with error: " . mysql_error() ); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } while ($row = mysql_fetch_assoc($result)) { echo $row["firstname"]; echo $row["lastname"]; echo $row["dob"]; } }//if(isset($_POST['submit'])) ?> <html> <body> <form action="login_success8.php" method="post"> <p> <input type="text" name="first" size="20" /> First name<br /> <input type="text" name="last" size="20" /> Last name<br /> <input name="dob" type="text" size="20" id="dob" /> Date of Birth<br /> <input type="submit" name="submit" value="Search" /> <input type="reset" value="Reset fields" /> </p> </form> </body> </html> I've got to be missing something pretty basic here.. considering the query is pretty basic. I'm trying to figure out how to pull a query as an array so I can compare it against another array (array_diff) I'm doing a mysql_fetch_array, and I'm getting an error ( mysql_fetch_array(): supplied argument is not a valid MySQL result resource): Quote $checker = "SELECT ID FROM edible_uses"; $result2 = mysql_fetch_array($checker) or die(mysql_error()); //echoing to see if I'm getting what I need. echo $row['ID']; I've done a mysql_query and I get results. The table name and all that is correct. I'm stumped. This seems like a pretty simple query? I tried mysql_fetch_assoc as well. Same result? I tried it with an extra set of parenthesis around it. nope. i already have the front page that calls the script, but its not letting me login, i don't see the problem i know its returning the rows from the database but i don't understand why its not letting me login and when i do get it to login messing around with the code everybody logs in as an admin, my database has, user, pass, and role inside admin, poweruser, and reg user but when i get it to log in everybody logs in as an admin, can someone please help me ? i even tried the error thing but that doesn't seem to work either ini_set('display_errors', 1); error_reporting(E_ALL); //echo ini_set('display_errors'); session_start(); $username = $_POST['username']; $password = $_POST['password']; if (mysql_connect("localhost", "root", "")) { //echo 'connect'; } else { echo 'failure'; } if (mysql_select_db("athentication")) { //echo 'connect'; } else { echo 'no connect'; } $result = mysql_query("SELECT * FROM login WHERE user = '$username'"); $rows = mysql_num_rows($result); $role = $rows['role']; if ($rows != 0) { if ($role == 'admin') { header('Location: admin.php'); $_SESSION['username'] = $username; } elseif ($role == 'poweruser') { header('Location: poweruser.php'); $_SESSION['username'] = $username; } /*elseif ($role ==' reg') { echo "WHAT UP"; $_SESSION['username'] = $username; }*/ } else echo "enter a valid user name"; |