jarvis
Members-
Posts
543 -
Joined
-
Last visited
Everything posted by jarvis
-
Hi all, I've got the following script which nicely creates my thumbnail at 120px high or wide. Rather than copy the original size image as well, I'd like the original resized to 800x600 I cannot see the best way to do this, so any help is much appreciated! Here's my code. function saveThumb($gal,$fn) { define("MAX_XY", 120); // maximum width or height of thumbnail image $fpath = "categories/$gal/$fn"; $info = GetImageSize("$fpath"); // do we need to resize image? if ($info[0] > MAX_XY || $info[1] > MAX_XY) { // is image landscape? if ($info[0] >= $info[1]) { $width = MAX_XY; $height = $info[1]*MAX_XY/$info[0]; // or portrait? } else { $height = MAX_XY; $width = $info[0]*MAX_XY/$info[1]; } } else { // use original dimensions $width = $info[0]; $height = $info[1]; } // create new thumbnail image $im = ImageCreateTrueColor($width, $height); $im_big = ""; // default is no image switch ($info[2]) { case 1 : if (ImageTypes() & IMG_GIF) // test for GIF support $im_big = ImageCreateFromGIF("$fpath"); break; case 2 : if (ImageTypes() & IMG_JPG) // test for JPEG support $im_big = ImageCreateFromJPEG("$fpath"); break; case 3 : if (ImageTypes() & IMG_PNG) // test for PNG support $im_big = ImageCreateFromPNG("$fpath"); break; case 4 : if (ImageTypes() & IMG_BMP) // test for BMP support $im_big = ImageCreateFromBMP("$fpath"); break; } if ($im_big) { /* resize original image into thumbnail - see PHP Manual for details on * the arguements ImageCopyResized takes */ ImageCopyResized($im,$im_big,0,0,0,0,$width,$height,$info[0],$info[1]); } else { // couldn't load original image, so generate 'no thumbnail' image instead $width = 120; $height = 120; $im = ImageCreate($width, $height); // create a blank image $bgc = ImageColorAllocate($im, 0, 0, 0); // background color = black $tc = ImageColorAllocate($im, 255, 255, 255); // text color = white ImageFilledRectangle($im, 0, 0, $width, $height, $bgc); // draw rectangle ImageString($im, 3, 9, 36, "No thumbnail", $tc); // add text ImageString($im, 3, 17, 48, "available", $tc); } /* save our image in thumb directory - if the second argument is left out, * the image gets sent to the browser, as in thumbnail.php */ ImageJPEG($im, "categories/".$gal."/t_".$fn); // clean up our working images ImageDestroy($im_big); ImageDestroy($im); } Thanks in advanced!
-
Hi all, Am going mad trying to get something to work. I'm creating a CMS for a magazine. The magazine is published every 2 months and therefore the edition is nov-dec or jan-feb etc. I've an archive option on the site and rather than listing: dec nov oct sept etc I'd like to follow the magazine editions: nov-dec sept-oct The code I have so far is: echo '<p>Sort By:</p>'; $year = date("Y"); //get the current year $startDate = "1 january".$year; // set the end date to current year function printMonths($var) { $start = strtotime($var); //timestamp of the entered date $now = strtotime("Now"); //timestamp of now so it does not write anything in the future while ($now > $start) //while the start is less than now { echo '<a href="news_archive.php?s=&id=' . get_id() . '&month=' . date("F", $now) .'">'.date("F", $now).'</a>'; echo " | "; $now = strtotime("-1 month", $now); // subtract a month from the start timestamp } } printMonths($startDate); //execute the function this works well listing the months from the current month back. But this is not what I need. If I alter the line $now = strtotime("-1 month", $now); to $now = strtotime("-2 month", $now); It starts in Nov and goes back to sept which is not right. It also doesn't show nov-dec etc. Any help on this is much appreciated! Thanks
-
Thanx bricktop, of course! I was working on the theory that as this was the edit page, you needed to retrieve the value and also display it! I'll go give that a bash!
-
Hi All, Probably very simple but; I've got fckeditor installed on a CMS, whenever you add an image or a link, it saves the info twice and seperate the entire duplicate content with Quote: " /> It's as if it's not closing a tag. Has anyone else had this or knows how to resolve it? Just as a subnote: My line of code is: Code: <td><textarea rows="20" name="content" cols="60" value="' . $row[4] . '" />' . $row[4] . '</textarea></td> The duplicate " /> is coming in from the above as I've removed the space in the above line so it's just "/> and this is then what appears in the duplicate text. Hmmm....
-
Thanks cags & apologies! Will try & get that working
-
Thanks cags, I can't seem to get that working though: <?php // Create category options $query = "SELECT * FROM categories ORDER BY category ASC"; $column_count = 5; $row_count = ceil(mysql_num_rows($query) / $column_count); echo '<table'; for($r = 0; $r < $row_count; ++$r) { // start row echo '<tr>'; for($c = 0; $c < $column_count; ++$c) { if(mysql_fetch_array($result, MYSQL_NUM)) { echo '<td><input type="checkbox" name="types[]" value="' . $row[1] . '" />' .$row[1] . '</td>'; } else { echo '<td> </td>'; } } // end row echo '</tr>'; } echo '</table>'; ?> Gives the error: Line 159: $row_count = ceil(mysql_num_rows($query) / $column_count); Sorry to sound thick!
-
Hi all, I've the following code <?php // Create category options $query = "SELECT * FROM categories ORDER BY category ASC"; $result = mysql_query ($query); while ($row = mysql_fetch_array ($result, MYSQL_NUM)) { echo "<input type=\"checkbox\" name=\"types[]\" value=\"$row[1]\">$row[1]\n"; } ?> This lists out up to 15 checkboxes, but can increase or decrease if more are added/removed. At present this simply produces a list. How can I alter the above to produce a nice table with say 5 checkboxes per row? Thanks
-
php/mysql auto logout after 2 hour and reset password
jarvis replied to jarvis's topic in PHP Coding Help
Ah, good point! Could that be hidden and included as a php include? That way it's only see server side? -
php/mysql auto logout after 2 hour and reset password
jarvis replied to jarvis's topic in PHP Coding Help
Could I use: <META HTTP-EQUIV="Refresh" content="600;url=http://mydomain.com/logout.php"> If I put this in the header, surely after 600 seconds it will redirect to my log out script? Or is this not deemed acceptable? -
php/mysql auto logout after 2 hour and reset password
jarvis replied to jarvis's topic in PHP Coding Help
Sorry to bring this one back up but I'm still having issues. In a nutshell, I need to kill my session, without the need of a page refresh after a set time period. It's not after inactivity, the site can be in use by someone but after say 2 hours will just end. Upon killing the session, I need to run a php script. is this possible? do i need to add the code to each page or just to my header? please see above for how I set up my session and the code used. thanks in advanced! -
Wicked! Thanks very much!! Simple when you know how
-
php/mysql auto logout after 2 hour and reset password
jarvis replied to jarvis's topic in PHP Coding Help
Hi all, OK, I've found this code which works well to time out a session without inactivity session_start(); //set timeout period in seconds $inactive = 30; // check to see if $_SESSION['timeout'] is set if(isset($_SESSION['timeout']) ) { $session_life = time() - $_SESSION['timeout']; if($session_life > $inactive) { session_destroy(); header("Location: logout.php"); } } $_SESSION['timeout'] = time(); How can I set it to auto expire after a set time? i've tried ini_set('session.gc_maxlifetime', 15); but that doesn't work. I placed that at the top of all pages. Any help is much apprciated! -
Hi All, Ok I've the following code to handle my image upload: // Check for an image. if (is_uploaded_file ($_FILES['image']['tmp_name'])) { // Relocate the image if (move_uploaded_file($_FILES['image']['tmp_name'], 'categories/'.$_POST['id'].'/'.$_FILES['image']['name'])) { saveThumb($_POST['id'],$_FILES['image']['name']); #$insert_sql = 'INSERT INTO uploads values("",'.$_POST['id'].', "'.$_FILES['image']['name'].'", "'.$_FILES['image']['size'].'", "'.$_FILES['image']['type'].'", "'.$_POST['image_description'].'", NOW())'; $insert_sql = 'INSERT INTO uploads values(NULL,'.$_POST['category'].', "'.$_FILES['image']['name'].'", "'.$_FILES['image']['size'].'", "'.$_FILES['image']['type'].'", "'.$_POST['image_description'].'", NOW())'; echo $insert_sql; $insert_rs = mysql_query($insert_sql) or die(mysql_error()); echo '<p class="error">The image has been uploaded!</p>'; } else { // Inform user if problem relocating image echo '<p class="error">The file could not be Uploaded!</p>'; } } else { echo '<p class="error">You must also select an image to upload!</p>'; } How can i stop the same file being uploaded twice? I figure the easiest way is to rename the file when uploading, how can I do this with the above code? Thanks in advanced!
-
php/mysql auto logout after 2 hour and reset password
jarvis replied to jarvis's topic in PHP Coding Help
Thanks GiriJ, that's more what I'm after. Would that be a session of 10 mins overall or per page if they remain on one page? Do I add that on each page? If this is an overall 10 mins, this is perfect as I can increase it to 2 hours. How could I then add in my pw reset? This is my code to create a random pw // Create a new, random password. $p = substr ( md5(uniqid(rand(),1)), 3, 10); // Make the query. $query = "UPDATE users SET pass=SHA('$p') WHERE user_id=$uid"; $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); if (mysql_affected_rows() == 1) { // If it ran OK. // Send an email. $body = "Your password to log into domain.co.uk has been temporarily changed to '$p'. Please log in using this password and your username. At that time you may change your password to something more familiar."; mail ($_POST['email'], 'Your temporary password.', $body, 'From: [email protected]'); echo '<h3>Your password has been changed. You will receive the new, temporary password at the email address with which you registered. Once you have logged in with this password, you may change it by clicking on the "Change Password" link.</h3>'; mysql_close(); // Close the database connection. include ('./includes/footer.html'); // Include the HTML footer. exit(); } I can pull the username from the session I guess? Thanks again! -
php/mysql auto logout after 2 hour and reset password
jarvis replied to jarvis's topic in PHP Coding Help
thanks fooDigi but as it's not a dedicated host I would need to do it via the script I think!? -
Hi all, This I hope will make sense. I've the following code which when a user logins in, creates a session: if (isset($_POST['submitted'])) { // Check if the form has been submitted. require_once ('mysql_connect.php'); // Connect to the database. // Validate the email address. if (!empty($_POST['email'])) { $e = escape_data($_POST['email']); } else { echo '<p class="error">You forgot to enter your email address!</p>'; $e = FALSE; } // Validate the password. if (!empty($_POST['pass'])) { $p = escape_data($_POST['pass']); } else { $p = FALSE; echo '<p class="error">You forgot to enter your password!</p>'; } if ($e && $p) { // If everything's OK. // Query the database. $query = "SELECT user_id, first_name, account_id FROM users WHERE (email='$e' AND pass=SHA('$p')) AND active IS NULL"; $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); if (@mysql_num_rows($result) == 1) { // A match was made. // Register the values & redirect. $row = mysql_fetch_array ($result, MYSQL_NUM); mysql_free_result($result); mysql_close(); // Close the database connection. $_SESSION['user_id'] = $row[0]; $_SESSION['first_name'] = $row[1]; $_SESSION['account_id'] = $row[2]; // Start defining the URL. $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } // Add the page. $url .= '/index.php'; ob_end_clean(); // Delete the buffer. header("Location: $url"); exit(); // Quit the script. } else { // No match was made. echo '<p class="error">Either the email address and password entered do not match those on file or you have not yet activated your account.</p>'; } } else { // If everything wasn't OK. echo '<p class="error">Please try again.</p>'; } mysql_close(); // Close the database connection. } // End of SUBMIT conditional. ?> <h1>Login</h1> <p class="maintext">Your browser must allow cookies in order to log in.</p> <form action="login.php" method="post"> <fieldset> <p class="maintext"><b>Email Address:</b> <input type="text" name="email" size="20" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p> <p class="maintext"><b>Password:</b> <input type="password" name="pass" size="20" maxlength="20" /></p> <div align="center"><input type="submit" name="submit" value="Login" /></div> <input type="hidden" name="submitted" value="TRUE" /> </fieldset> </form> Each page I want protected then has this at the top // If no first_name variable exists, redirect the user. if (!isset($_SESSION['first_name'])) { // Start defining the URL. $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } // Add the page. $url .= '/index.php'; ob_end_clean(); // Delete the buffer. header("Location: $url"); exit(); // Quit the script. } else { ### page ### } What I'd like to do is set the session to automatically expire after 2 hours and the users password to reset to something different to prevent login. I assume this is possible but where do I start?
-
Hi all, We've a basic site cms which allows properties to be uploaded. Works well in php/mysql. The client is thinking of adding to rightmove and/or property finder and maybe fish4. How easy is it to integrate with theses companies or do you pay them a monthly fee and they do that bit for you? Thanks
-
I don't really want to go down the WAMP route if I can help it but fast losing hair at this rate!
-
I wonder if the version of php I have is not compiled with mysql? Under the configure command, it's not listed:
-
Yep, the ini file is in my C:/php5 dir
-
@zanus, I can check the phpinfo file but it's not showing anything about MySQL and I believe it should. This would more than likely explain why PHPMyAdmin is not working!
-
Hi thorpe, I've just checked and mysql only shows here: There is no seperate header which I thought there should be!? My php.ini file has the following I also have the following extensions Is there anything else I can check? Thanks
-
Hi all, I'm trying to install PHPMyAdmin but get the annoying error: I'm running a PC with win xp pro Apache 2.0.63 PHP 5.2.10 MySQL 5.1.38 PHPMyAdmin 3.2.1 Apache, PHP and MySQL run fine on there own. It's simply PHPMyAdmin not playing ball. My config file shows [php <?php $i = 1; #$cfg['http://localhost/phpMyAdmin'] = 'http://localhost/phpMyAdmin/'; $cfg['Servers'][$i]['extension'] = 'mysqli'; $cfg['Servers'][$i]['password'] = 'password'; ?> [/code] I've not copied any lib.dll files into the C:|windows or sysem32 dir. I've also got the libmysql.dll and libmysqli.dll files in my php dir. Is there anything I can check or do? many thanks
-
Thanks syed, I'd rather code it as I can then get the output to work inline with the correct number of outputted files from the db. i.e. if it return10 images, I'd have 2 lines of 5. If only 3 images were in the db, I'd have 1 row of 3 etc. Similarly, 50 images, 10 rows of 5!
-
Hi all, I've the following code which shows a form. The form loops through 10 input fields. Pulling info from the db it will show say 5 images if only 5 have been uploaded and another 5 input fields making the 10 uploads. // Create the inputs. for ($i = 0; $i < MAX_IMAGE_UPLOADS; $i++) { $image_row = mysql_fetch_row($uploaded_image_details_rs); if(!empty($image_row[0])) { $this_image = '<img src="categories/'.$_REQUEST['id'].'/'.$image_row[0].'" width="150" />'."\n\n"; $this_image .= '<br />'."\n\n"; $this_image .= ''."\n\n"; } else { $this_image = 'No Image'; } if(!empty($image_row[1])) { $this_image_description = $image_row[1]; } else { $this_image_description = ''; } echo ' <form enctype="multipart/form-data" action="edit_category_image.php" method="post"> <table width="100%" border="0"> <tr> <td valign="top"><p><b> File '.($i + 1).':</b><br /> <input type="file" name="image" /><br /> <div align="center">'; if(!empty($image_row[0])) echo '<a href="./edit_category_image.php?id='.$_REQUEST['id'].'&del='.$image_row[2].'" onclick="return confirm(\'Do you really want to delete this image?\');">Delete Image and Description</a> </div>'; echo'</p></td> <td valign="top"><p><b> Image Description '.($i + 1).':</b><br /> <textarea name="image_description" cols="25" rows="3">'.$this_image_description.'</textarea> </p></td> </tr> <tr> <td width="150"><div align="center"> Image '.($i + 1).':<br />'.$this_image.' </div></td> <td><div align="center">'; if(!empty($image_row[0])) echo '<input type="submit" value="- Update -" />'; else echo '<input type="submit" value="- Upload -" />'; echo '</div></td></tr> </table> <input type="hidden" name="submit_type" value="'; if(!empty($image_row[0])) { echo 'update" />'."\n\n"; echo '<input type="hidden" name="this_image_id" value="'.$image_row[2].'" />'."\n\n"; } else echo 'upload" />'."\n\n"; echo ' <input type="hidden" name="submitted" value="TRUE" /> <input type="hidden" name="id" value="' . $id . '" /> <input type="hidden" name="MAX_FILE_SIZE" value="104976"> </form> <hr style="border:dotted black 1px;" /> '; } At the mo, it shows the form in a list down the page. What I'd like to do is show the images in a table 5 columns by X rows. As the number of image fields could increase to say 15 it will be great if the loop takes care of it. I've no idea where to start. Any help is much appreciated!