jarvis
Members-
Posts
543 -
Joined
-
Last visited
Everything posted by jarvis
-
Hi, When I copy an image, my script then has the following to copy the image to it's location: ImageJPEG($im, "categories/".$gal."/t_".$fn); To improve the quality, do I simply add a third parameter for the quality level? i.e. ImageJPEG($im, "categories/".$gal."/t_".$fn, 75); Either 75 - 100 with 100 being best, is that right?
-
Sorry to bump but I'm struggling with this, any helps much appreciated!
-
Hi All, Following on fropm the above, do I need to run the script in several parts? - check image size - resize for large - create large - crop - resize - create thumb Or is it easier than that? thanks
-
Hi all, I use the following script to resize my images to either 150 high or wide and 800 high or wide What I need to do, is set the thumbnail to be 150 x 150 and take a crop of the main image and resize the main to 800px high or wide. how can I alter the below to do this? <?php function saveThumb($gal,$fn) { define("MAX_XY_SMALL", 150); // maximum width or height of thumbnail image define("MAX_XY_LARGE", 800); // maximum width or height of thumbnail image $fpath = "categories/$gal/$fn"; //print $fpath."\n"; /* GetImageSize returns an array: * $info[0] - horizontal size of image in pixels * $info[1] - vertical size of image in pixels * $info[2] - type of image (1=GIF, 2=JPEG, 3=PNG) */ $info = GetImageSize("$fpath"); //print_r($info); // do we need to resize image? if ($info[0] > MAX_XY_SMALL || $info[1] > MAX_XY_SMALL) { // is image landscape? if ($info[0] >= $info[1]) { $width = MAX_XY_SMALL; $height = $info[1]*MAX_XY_SMALL/$info[0]; // or portrait? } else { $height = MAX_XY_SMALL; $width = $info[0]*MAX_XY_SMALL/$info[1]; } } else { // use original dimensions $width = $info[0]; $height = $info[1]; } if ($info[0] > MAX_XY_LARGE || $info[1] > MAX_XY_LARGE) { // is image landscape? if ($info[0] >= $info[1]) { $width_large = MAX_XY_LARGE; $height_large = $info[1]*MAX_XY_LARGE/$info[0]; // or portrait? } else { $height_large = MAX_XY_LARGE; $width_large = $info[0]*MAX_XY_LARGE/$info[1]; } } else { // use original dimensions $width_large = $info[0]; $height_large = $info[1]; } // create new thumbnail image //echo "<br>$width - $height<br>"; $im = ImageCreateTrueColor($width, $height); $im_large = ImageCreateTrueColor($width_large, $height_large); /* determine image type and load original image. Notice new tests for image * types. The GD extension has changed a lot over the years, dropping GIFs * and adding PNG support. By testing, we avoid trying to process an image * PHP can't deal with */ $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]); ImageCopyResized($im_large,$im_big,0,0,0,0,$width_large,$height_large,$info[0],$info[1]); } else { // couldn't load original image, so generate 'no thumbnail' image instead $width = 150; $height = 150; $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); ImageJPEG($im_large, "categories/".$gal."/".$fn); // clean up our working images ImageDestroy($im_big); ImageDestroy($im); ImageDestroy($im_large); } ?> Thanks in advanced!
-
Ok, I've sorted that issue. Problem I've got now, when I update the image, I want to remove the old one. However, it errors as its says rename(categories/11/window.jpg,categories/11/window.jpg) [function.rename]: No such file or directory Where window.jpg is the old image. I think it's obvious but cannot see for looking. My code is below: if(!empty($_POST['submit_type']) && $_POST['submit_type'] == 'update') { // Get the category if (!empty($_POST['category'])) { $category = escape_data($_POST['category']); } // Check for an image. if (is_uploaded_file ($_FILES['image']['tmp_name'])) { //remove old image and replace with new $R=mysql_query("SELECT * FROM uploads WHERE upload_id = ".$_POST['this_image_id']); echo $R; $O=mysql_fetch_object($R); $category_id=$O->category_id; $fname=$O->file_name; $tfname="t_".$fname; @unlink("categories/$category_id/$fname"); @unlink("categories/$category_id/$tfname"); // Relocate the image if (move_uploaded_file($_FILES['image']['tmp_name'], 'categories/'.$_POST['id'].'/'.$_FILES['image']['name'])) { saveThumb($_POST['id'],$_FILES['image']['name']); $update_sql = 'UPDATE uploads SET category_id = "'.escape_data($_POST['category']).'", image_description = "'.escape_data($_POST['image_description']).'", file_type = "'.$_FILES['image']['type'].'", file_size = "'.$_FILES['image']['size'].'", file_name = "'.$_FILES['image']['name'].'" where upload_id = '.$_POST['this_image_id']; #echo $update_sql; $update_rs = mysql_query($update_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>'; } } //RELOCATE THE IMAGE IF REQUIRED if (!empty($_POST['image_name'])) { $image_name = escape_data($_POST['image_name']); } //UPDATE IMAGE AND DESCRIPTION ALREADY SET IN DATABASE. $update_sql = 'UPDATE uploads SET category_id = "'.escape_data($_POST['category']).'", image_description = "'.escape_data($_POST['image_description']).'" WHERE upload_id = '.$_POST['this_image_id']; #echo $update_sql .' update and relocate'; $update_rs = mysql_query($update_sql) or die(mysql_error()); #if ($update_rs){ $original = 'categories/'.$id.'/'.$image_name; $original_t = 'categories/'.$id.'/t_'.$image_name; $copied = 'categories/'.$_POST['category'].'/'.$image_name; $copied_t = 'categories/'.$_POST['category'].'/t_'.$image_name; rename($original, $copied); rename($original_t, $copied_t); #} } else { //INSERT NEW IMAGE AND DESCRIPTION INTO DATABASE. if(!empty($_POST['submit_type']) && $_POST['submit_type'] == 'upload') { Thanks again!
-
Would I be better off adding another option: update relocate <-- new upload I could then do: if (!empty($_POST['submit_type']) && $_POST['submit_type'] == 'update') { #update } elseif (!empty($_POST['submit_type']) && $_POST['submit_type'] == 'relocate') { #relocate } else { #upload }
-
Hi All, Hope some kind soul can help, I think I've got myself in a muddle! I've a form which: If an image exists, you can delete it or update it. The update can be either: a) The image b) the description or c) the category it's in. If no image exists, you can add a new image and description. Currently, the adding a new image works. It's the if existing image update fails. My code: if(!empty($_POST['submit_type']) && $_POST['submit_type'] == 'update') { // Get the category if (!empty($_POST['category'])) { $category = escape_data($_POST['category']); } // Check for an image. if (is_uploaded_file ($_FILES['image']['tmp_name'])) { // Relocate the image if (move_uploaded_file($_FILES['image']['tmp_name'], '../uploads/'.$_POST['id'].'/'.$_FILES['image']['name'])) { saveThumb($_POST['id'],$_FILES['image']['name']); $update_sql = 'UPDATE uploads SET category_id = "'.escape_data($_POST['category']).'", image_description = "'.escape_data($_POST['image_description']).'", file_type = "'.$_FILES['image']['type'].'", file_size = "'.$_FILES['image']['size'].'", file_name = "'.$_FILES['image']['name'].'" where upload_id = '.$_POST['this_image_id']; echo $update_sql; $update_rs = mysql_query($update_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>'; } } //UPDATE IMAGE AND DESCRIPTION ALREADY SET IN DATABASE. $update_sql = 'UPDATE uploads SET category_id = "'.escape_data($_POST['category']).'", image_description = "'.escape_data($_POST['image_description']).'" WHERE upload_id = '.$_POST['this_image_id']; //RELOCATE THE IMAGE IF REQUIRED if (!empty($_POST['image_name'])) { $image_name = escape_data($_POST['image_name']); } $original = 'categories/'.$id.'/'.$image_name; $original_t = 'categories/'.$id.'/t_'.$image_name; $copied = 'categories/'.$_POST['category'].'/'.$image_name; $copied_t = 'categories/'.$_POST['category'].'/t_'.$image_name; rename($original, $copied); rename($original_t, $copied_t); } else { //INSERT NEW IMAGE AND DESCRIPTION INTO DATABASE. if(!empty($_POST['submit_type']) && $_POST['submit_type'] == 'upload') { ...code to upload new Please can someone point out where I've gone wrong. many thanks
-
Hi all, Hope someone can point out the obvious. I've a log in script, if you dont enter a username or pw, you get a red asterix show by the field and a pop up. If you enter an email but not the pw, it says Undefined variable: email_error . This is the code: // Validate the email address. if (!empty($_POST['email'])) { $e = escape_data($_POST['email']); } else { echo '<script type="text/javascript">alert("You forgot to enter your email address!");</script>'; #echo '<p class="error">You forgot to enter your email address!</p>'; $e = FALSE; $email_error = '<span class="required"><img src="images/star.gif" /></span>'; } // Validate the password. if (!empty($_POST['pass'])) { $p = escape_data($_POST['pass']); } else { $p = FALSE; echo '<script type="text/javascript">alert("You forgot to enter your password!");</script>'; $pw_error = '<span class="required"><img src="images/star.gif" /></span>'; #echo '<p class="error">You forgot to enter your password!</p>'; } My form looks like: <form action="login.php" method="post"> <table border="0" width="310"> <tr> <td><img src="images/email_address.gif" /></td> <td><div class="myBoxLh"></div><input type="text" name="email" style="width:150px;" maxlength="90" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /><div class="myBoxRh"></div><?php if (isset($_POST['submitted'])) { echo $email_error; }?></td> </tr> <tr> <td><img src="images/password.gif" /></td> <td><div class="myBoxLh"></div><input type="password" name="pass" style="width:150px;" maxlength="20" /><div class="myBoxRh"></div><?php if (isset($_POST['submitted'])) { echo $pw_error; }?></td> </tr> <tr> <td colspan="2"><div align="left"><?php if (isset($_POST['submitted'])) { echo $error_message; }?></div><div align="right"><input type="image" src="images/submit.jpg" name="submit" value="Login" class="submit_small" /></div> <input type="hidden" name="submitted" value="TRUE" /></td> </tr> </table> </form> How can I stop this error as I thought I'd coded the correct way? Thanks in advanced!
-
Hi all, Got the following code: if (mysql_affected_rows() == 1) { echo "<div align=\"center\"><img src=\"images/account_active.gif\"></div>"; $query1 = "SELECT email, pass FROM users WHERE (user_id=$x) LIMIT 1"; $result1 = mysql_query ($query1) or trigger_error("Query: $query1\n<br />MySQL Error: " . mysql_error()); $email = $row[0]; $pw = $row[1]; When it runs, I get Undefined variable: row on line 44 which is $email = $row[0]; Please point out the obvious as to why and what I need to do. I can't think straight anymore Thanks
-
Think I've sussed this one out, the session was acc_type and the edit user code also referenced acc_type so I just renamed the code to account_type and this left acc_type as the session name. Seems to work!
-
Hi All, I hope someone can point out the obvious with this one. I've a CMS which has 2 account types: - Admin - Basic If you're logged in as an admin, you can edit a user and you've access to other parts of the CMS If you're logged in as a basic user, you just get access to 1 page My problem is, when I edit a user with basic access, as soon as I go into the edit user screen, the CMS removes all access as if you were logged in as the basic user. There are 3 parts to the script - header - edit_user - footer Header contains // This page begins the HTML header for the site. // Start output buffering. ob_start(); // Initialize a session. session_start(); edit_user contains <?php // This page edits a users profile // This page is accessed through view_users.php. // Include the configuration file for error management and such. require_once ('includes/config.inc.php'); // Set the page title and include the HTML header. $page_title = 'Edit A Profile'; include ('includes/header.html'); // If no first_name variable exists, redirect the user. if (!isset($_SESSION['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 { ?> <!-- box_top --> <div id="box_top"> <img src="images/login_box_top.jpg"> </div> <!-- /box_top --> <!-- general --> <div id="general"> <div id="general_scrollarea"> <?php // Check for a valid user ID, through GET or POST if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { // Accessed through view_users.php $id = $_GET['id']; } elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) { // Form has been submitted $id = $_POST['id']; } else { // No valid ID, terminate the script here and inform user echo '<h1>Page Error</h1> <p class="error">This page has been accessed in error.</p><p><br /><br /></p>'; require('includes/footer.html'); exit(); } require_once('../mysql_connect.php');// Connect to the db // Check if the form has been submitted if (isset($_POST['submitted'])) { // Check for a name. if (eregi ('^[[:alpha:]\.\' \-]{2,15}$', stripslashes(trim($_POST['name'])))) { $name = escape_data($_POST['name']); } else { $name = FALSE; echo '<p>Please enter your name!</p>'; } // Check for a position if (!empty($_POST['position'])) { $position = escape_data($_POST['position']); } else { $position = FALSE; echo '<p class="error">Please enter a position!</p>'; } // Check for a company if (!empty($_POST['company'])) { $company = escape_data($_POST['company']); } else { $company = FALSE; echo '<p class="error">Please enter a company!</p>'; } // Check for a address if (!empty($_POST['address'])) { $address = escape_data($_POST['address']); } else { $address = FALSE; echo '<p class="error">Please enter an address!</p>'; } // Check for a postcode if (!empty($_POST['postcode'])) { $postcode = escape_data($_POST['postcode']); } else { $postcode = FALSE; echo '<p class="error">Please enter a postcode!</p>'; } // Check for a country if (!empty($_POST['country'])) { $country = escape_data($_POST['country']); } else { $country = FALSE; echo '<p class="error">Please enter a country!</p>'; } // Check for a telephone if (!empty($_POST['telephone'])) { $telephone = escape_data($_POST['telephone']); } else { $telephone = FALSE; echo '<p class="error">Please enter a telephone!</p>'; } // Check for an email address. if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['email'])))) { $email = escape_data($_POST['email']); } else { $email = FALSE; echo '<p>Please enter a valid email address!</p>'; } // Check for a design requirement if (!empty($_POST['requirements'])) { $requirements = escape_data($_POST['requirements']); } else { $requirements = FALSE; echo '<p class="error">Please enter your design requirements!</p>'; } // Check the account type if(isset($_POST['acc_type'])){ $acc_type = $_POST['acc_type']; } else { $acc_type = '0'; } // Check for a category. if (isset($_POST['types']) && (is_array($_POST['types']))) { $type = TRUE; } else { $type = FALSE; echo '<p class="error">Please select at least one user category!</p>'; } // Check for a collection type if (!empty($_POST['collection'])) { $collection = escape_data($_POST['collection']); } else { $collection = FALSE; echo '<p class="error">Please enter your collection type!</p>'; } if ($type && $name && $email) { // Test for unique user $query = "SELECT user_id FROM users WHERE email='$email'AND user_id != $id"; $result = mysql_query($query); if (mysql_num_rows($result) == 0) { // Make the query. // Update the articles table. $query1 = "UPDATE users SET name='$name', position='$position', company='$company', address='$address', postcode='$postcode', country='$country', telephone='$telephone', email='$email', requirements='$requirements', acc_type='$acc_type', collection='$collection' WHERE user_id=$id"; #echo $query1; $result1 = mysql_query($query1); // Update the category_associations table. // Retrieve the old categories. $exist_types = unserialize(urldecode($_POST['exist_types'])); if ($_POST['types'] != $exist_types) { // A category change was made. // Determine the new and old categories. $add = array_diff($_POST['types'], $exist_types); $delete = array_diff($exist_types, $_POST['types']); // Add new types, if needed. if (!empty($add)) { $query2 = 'INSERT INTO user_associations (user_id, category_id, approved) VALUES '; foreach ($add as $v) { $query2 .= "($id, $v, 'Y'), "; } $query2 = substr ($query2, 0, -2); // Chop off the last comma and space. $result2 = mysql_query ($query2); // Run the query. } else { // No new types. $result2 = TRUE; } // Delete old types, if necessary. if (!empty($delete)) { $query3 = "DELETE FROM user_associations WHERE (user_id=$id) AND (category_id IN (". implode (',', $delete) . "))"; $result3 = mysql_query($query3); } else { // No old types. $result3 = TRUE; } } else { // No category changes being made. $result2 = TRUE; $result3 = TRUE; } // Report on the success. if ($result1 && $result2 && $result3) { echo '<p class="confirm"><b>The user has been edited!</b></p>'; } else { #echo '<p clas="error">Your submission could not be processed due to a system error. We apologize for any inconvenience.</p>'; echo '<p class="confirm">The categories have been added!</p>'; // Print queries and use the mysql_error() function (after each mysql_query() call) to debug. } } else { // If one of the data tests failed. echo '<p class="error">That email address has been registered already</p>'; } } } // End of submit conditional // Display the form // Retrieve the properties information $query = "SELECT name, position, company, address, postcode, country, telephone, email, requirements, acc_type, collection, category_id FROM users LEFT JOIN user_associations USING (user_id) WHERE users.user_id=$id"; #echo $query; $result = @mysql_query ($query); // Process the query // Get all of the information for the first record. $exist_types = array(); // Reset. list($name, $position, $company, $address, $postcode, $country, $telephone, $email, $requirements, $acc_type, $collection, $exist_types[]) = mysql_fetch_array ($result, MYSQL_NUM); // Get the other article_category_id values. while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $exist_types[] = $row[11]; } ?> <form action="edit_user.php" method="post"> <table width="500px" align="center"> <tr> <td align="right"><img src="images/name.gif" /></td> <td><div class="myBoxLh"></div><input type="text" name="name" value="<?php echo $name; ?>" size="30" /><div class="myBoxRh"></div></td> </tr> <tr> <td align="right"><img src="images/position.gif" /></td> <td><div class="myBoxLh"></div><input type="text" name="position" value="<?php echo $position; ?>" size="30" /><div class="myBoxRh"></div></td> </tr> <tr> <td align="right"><img src="images/company.gif" /></td> <td><div class="myBoxLh"></div><input type="text" name="company" value="<?php echo $company; ?>" size="30" /><div class="myBoxRh"></div></td> </tr> <tr> <td align="right"><img src="images/address.gif" /></td> <td><div class="myBoxLhLarge"></div><textarea name="address" cols="13" rows="2" value="<?php echo $address; ?>"><?php echo $address; ?></textarea><div class="myBoxRhLarge"></div></td> </tr> <tr> <td align="right"><img src="images/postcode.gif" /></td> <td><div class="myBoxLh"></div><input type="text" name="postcode" value="<?php echo $postcode; ?>" size="30" /><div class="myBoxRh"></div></td> </tr> <tr> <td align="right"><img src="images/country.gif" /></td> <td><div class="myBoxLh"></div><input type="text" name="country" value="<?php echo $country; ?>" size="30" /><div class="myBoxRh"></div></td> </tr> <tr> <td align="right"><img src="images/telephone.gif" /></td> <td><div class="myBoxLh"></div><input type="text" name="telephone" value="<?php echo $telephone; ?>" size="30" /><div class="myBoxRh"></div></td> </tr> <tr> <td align="right"><img src="images/email.gif" /></td> <td><div class="myBoxLh"></div><input type="text" name="email" value="<?php echo $email; ?>" size="30" /><div class="myBoxRh"></div></td> </tr> <tr> <td align="right"><img src="images/design_requirements.gif" /></td> <td><div class="myBoxLhLarge"></div><textarea name="requirements" cols="13" rows="2" value="<?php echo $requirements; ?>"><?php echo $requirements; ?></textarea><div class="myBoxRhLarge"></div></td> </tr> <tr> <td align="right">collection:</td> <td> <input name="collection" type="radio" <?php if($collection == 'print'){ echo 'checked="checked"'; } ?> value="print" />Print<br/> <input name="collection" type="radio" <?php if($collection == 'licence'){ echo 'checked="checked"'; } ?> value="licence" />Licence </td> </tr> <tr> <td align="right">User Category/Categories:</td> <td> <select name="types[]" multiple="multiple" size="5"> <?php // Create the pull-down menu information. #require_once ('../mysql_connect.php'); $query = "SELECT * FROM categories ORDER BY category ASC"; $result = @mysql_query ($query); while ($row = mysql_fetch_array ($result, MYSQL_NUM)) { echo "<option value=\"$row[0]\""; // Make sticky, if necessary. if (in_array($row[0], $exist_types)) { echo ' selected="selected"'; } echo ">$row[1]</option>\n"; } ?> </select> </td> </tr> <tr> <td align="right">Account Type:</td> <td> <select name="acc_type"> <option value="0" <?php if($acc_type == '0'){ echo 'selected="selected"'; }else{ echo ''; } ?>>Basic</option> <option value="1" <?php if($acc_type == '1'){ echo 'selected="selected"'; }else{ echo ''; } ?>>Admin</option> </select> </td> </tr> <tr> <td colspan="2" align="right"> <div align="center"><input type="image" src="images/submit.jpg" name="submit" value="Update" class="submit" /></div></td> </tr> </table> <?php echo ' <input type="hidden" name="submitted" value="TRUE" /> <input type="hidden" name="id" value="' . $id . '" /> <input type="hidden" name="exist_types" value="' . urlencode(serialize($exist_types)) . '" />'; ?> </form> </div> </div> <!-- /general --> <?php mysql_close(); // Close the db connection require('includes/footer.html'); //end of the check authorised user function } ?> Footer contains <?php // Display links based upon the login status. // Show LOGIN links if this is the LOGOUT page. if (isset($_SESSION['user_id']) && ($_SESSION['acc_type']=="1") && (substr($_SERVER['PHP_SELF'], -10) != 'logout.php')) { echo ' <a href="logout_admin.php">Logout</a> | <a href="change_password.php">Change Password</a> | <a href="add_category.php">Add A Category</a> | <a href="view_categories.php">Edit A Category</a> | <a href="view_users.php">Edit A User</a> | <a href="forgot_password.php">Reset User Passwords</a> | <a href="licence.php">Licence Categories</a> | <a href="print.php">Print Categories</a> | <a href="admin_register.php">Create Account</a> | <a href="export.php" target="_blank">Export users</a> '; } elseif (isset($_SESSION['user_id']) && ($_SESSION['acc_type']=="0") && (substr($_SERVER['PHP_SELF'], -10) != 'logout.php')) { echo 'basic rights only'; } else { // Not logged in. echo ' <a href="register.php">Register</a> | <a href="request.php">Request New Password</a> | <a href="login.php">Login</a>'; } ?> </div> </body> </html> <?php // Flush the buffered output. ob_flush(); ?> Please help as this is driving me mad! Thanks in advanced!
-
Thanks Cags! That was exactly what I was after!
-
Hi, Hope you can help & this makes sense. When a user registers on my site, they select a radio button for: licence print This stores the selection in the db as text rather than 1 or 0 When I edit the user, i'd like to use the radio button again, however, depending what they selected initially, needs to be the default value. i.e. they selected print when they joined, so when I edit that user, the radio button print is checked. My code is below but won't work. Please help <input name="collection" type="radio" value="<?php if($collection == 'print'){ echo 'checked="checked"'; }else{ echo ''; } ?>">Print <input name="collection" type="radio" value="<?php if($collection == 'licence'){ echo 'checked="checked"'; }else{ echo ''; } ?>">Licence Thanks in advanced
-
Hi, It was the first_name not name issue in the logout script! Thank you so much!
-
Hi PFMaBiSmAd What will those lines of code show? Also, that is an error on my part, the logout script shouldn't used first_name but name. As for the new password on signout, this is something that's required. The idea is that when they logout, the password is reset & the member has to request a new log in. Something the client wanted! Thanks
-
Ok, here's 4 scripts: - login - a secure page - the header include - logout Login ***** <?php // This is the login page for the site. // Include the configuration file for error management and such. require_once ('./includes/config.inc.php'); // Set the page title and include the HTML header. $page_title = 'Login'; include ('./includes/header.html'); 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, name, acc_type 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['name'] = $row[1]; $_SESSION['acc_type'] = $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 .= '/category.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. ?> Secure page *********** <?php // This page allows users to add categories to the database. // Set the page title and include the HTML header. $page_title = 'Add a Category'; include ('./includes/header.html'); include('saveThumbCategories.php'); // If no first_name variable exists, redirect the user. if (!isset($_SESSION['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 { ?> The header include has ********************** <?php // This page begins the HTML header for the site. // Start output buffering. ob_start(); // Initialize a session. session_start(); ?> <!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" xml:lang="en" lang="en"> <head> Logout ****** <?php // This is the logout page for the site. // Include the configuration file for error management and such. require_once ('./includes/config.inc.php'); // Set the page title and include the HTML header. $page_title = 'Logout'; include ('./includes/header.html'); // 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 { // Logout the user. $user_id = $_SESSION['user_id']; require_once('../mysql_connect.php');// Connect to the db // 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=$user_id"; $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); if (mysql_affected_rows() == 1) { // If it ran OK. #echo 'pw reset'; } // Send an email. $body = "Your password to log into Lemon Ribbon 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]'); mail ('[email protected]', '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. $_SESSION = array(); // Destroy the variables. session_destroy(); // Destroy the session itself. setcookie (session_name(), '', time()-300, '/', '', 0); // Destroy the cookie. } // Print a customized message. echo "<h3>You are now logged out.</h3>"; include ('./includes/footer.html'); ?> Does that help at all? Thank you for your time & assistance on this, it's very much appreciated!
-
Sorry, the code on the pages is like: // If no first_name variable exists, redirect the user. if (!isset($_SESSION['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 { //run the script... Some pages use an id as well depending on what rights the user has. THANKS
-
Hi MadTechie, They do still have there rights. The code on my login page is // Query the database. $query = "SELECT user_id, name, acc_type 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['name'] = $row[1]; $_SESSION['acc_type'] = $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 .= '/category.php'; ob_end_clean(); // Delete the buffer. header("Location: $url"); exit(); // Quit the script. Does that help?
-
Hi All, I've got a cms that members can log into. When they logout, the session is destroyed, however, if you click the back button, you can get back into the CMS. How can I get around this? My logout code has $_SESSION = array(); // Destroy the variables. session_destroy(); // Destroy the session itself. setcookie (session_name(), '', time()-300, '/', '', 0); // Destroy the cookie. I've also tried adding this to my header file // HTTP/1.1 header("cache-Control: no-store, no-cache, must-revalidate"); header("cache-Control: post-check=0, pre-check=0", false); // HTTP/1.0 header("Pragma: no-cache"); // Date in the past header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // always modified header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // This page begins the HTML header for the site. // Start output buffering. ob_start(); // Initialize a session. session_start(); Am i doing something wrong? thanks
-
Hi guys, I really hope someone can help. I've got the following 2 scripts. The first handles my resizing and the second adds a watermark: <?php function saveThumb($gal,$fn) { define("MAX_XY_SMALL", 120); // maximum width or height of thumbnail image define("MAX_XY_LARGE", 800); // maximum width or height of thumbnail image $fpath = "categories/$gal/$fn"; //print $fpath."\n"; /* GetImageSize returns an array: * $info[0] - horizontal size of image in pixels * $info[1] - vertical size of image in pixels * $info[2] - type of image (1=GIF, 2=JPEG, 3=PNG) */ $info = GetImageSize("$fpath"); //print_r($info); // do we need to resize image? if ($info[0] > MAX_XY_SMALL || $info[1] > MAX_XY_SMALL) { // is image landscape? if ($info[0] >= $info[1]) { $width = MAX_XY_SMALL; $height = $info[1]*MAX_XY_SMALL/$info[0]; // or portrait? } else { $height = MAX_XY_SMALL; $width = $info[0]*MAX_XY_SMALL/$info[1]; } } else { // use original dimensions $width = $info[0]; $height = $info[1]; } if ($info[0] > MAX_XY_LARGE || $info[1] > MAX_XY_LARGE) { // is image landscape? if ($info[0] >= $info[1]) { $width_large = MAX_XY_LARGE; $height_large = $info[1]*MAX_XY_LARGE/$info[0]; // or portrait? } else { $height_large = MAX_XY_LARGE; $width_large = $info[0]*MAX_XY_LARGE/$info[1]; } } else { // use original dimensions $width_large = $info[0]; $height_large = $info[1]; } // create new thumbnail image //echo "<br>$width - $height<br>"; $im = ImageCreateTrueColor($width, $height); $im_large = ImageCreateTrueColor($width_large, $height_large); /* determine image type and load original image. Notice new tests for image * types. The GD extension has changed a lot over the years, dropping GIFs * and adding PNG support. By testing, we avoid trying to process an image * PHP can't deal with */ $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]); ImageCopyResized($im_large,$im_big,0,0,0,0,$width_large,$height_large,$info[0],$info[1]); } else { // couldn't load original image, so generate 'no thumbnail' image instead $width = 150; $height = 150; $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); ImageJPEG($im_large, "categories/".$gal."/".$fn); // clean up our working images ImageDestroy($im_big); ImageDestroy($im); ImageDestroy($im_large); } ?> The below is my watermark script $imagesource = $_GET['path']; $filetype = substr($imagesource,strlen($imagesource)-4,4); $filetype = strtolower($filetype); if($filetype == ".gif") $image = @imagecreatefromgif($imagesource); if($filetype == ".jpg") $image = @imagecreatefromjpeg($imagesource); if($filetype == ".png") $image = @imagecreatefrompng($imagesource); if (!$image) die(); $watermark = @imagecreatefromgif('watermark.gif'); $imagewidth = imagesx($image); $imageheight = imagesy($image); $watermarkwidth = imagesx($watermark); $watermarkheight = imagesy($watermark); $startwidth = (($imagewidth - $watermarkwidth)/2); $startheight = (($imageheight - $watermarkheight)/2); imagecopy($image, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight); imagejpeg($image); imagedestroy($image); imagedestroy($watermark); Is there a way to combine the 2 so that the watermark is added to the larger resized file. Also, I notice my watermark script isn't writing the watermark to the image, it simply adds it on the screen over the top, meaning you can download the image without problems. How can I sort this too? Thanks sooo much!
-
Hi all, Ok I've worked out my above query but I do have another - sorry! At the mo the links are: jan - feb mar - apr etc What I need to do is go dec (08) - Jan (09) feb - mar apr - may I need to start one month back in theory, so the year end link is oct-nov then starts dec 09 - jan 10 I dont need to show the year, it's just to illustrate this Thanks again, all help is much appreciated!!
-
thanks again darkvengance, i'll go take a look! Cheers
-
Thanks darkvengance that's very kind! Although it doesn't check for image types and looks like it doesn't generate 2 images. I need the thumb & the original but need to resize both. Maybe even copy the original too (just incase!) Thanks
-
Thanks Sasa, that's awesome! I've been going mad trying to suss that one out! I've one question though, in my old script, I used the month to pass it into my query. with the following code // Set the sorting order by months if (isset($_GET['month'])) { // $month will be appended to the links $month = $_GET['month']; } else { // Set a default sorting month to current month $month= date('F'); } Then passed that into my query with AND DATE_FORMAT(articles.date_entered,'%M') = '$month' As the link now shows Nov-Dec, I noticed when you hover over it, month it set to Nov, or the first month out the pair, i.e. sept-oct the link is sept. How can I also grab the oct and pass it into the query? The reason I ask, is if the articles were added in oct not sept, then no articles will show for the sept-oct edition. I hope that makes sense?