Jump to content

andrew_biggart

Members
  • Posts

    363
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by andrew_biggart

  1. Not sure if this is making a difference but I think there may be a problem with how you are declaring your variables. Try changing this: $vendor = ($_POST['vendor']); $date = ($_POST['date']); $invoice = ($_POST['invoice']); $total = ($_POST['total']); $tax = ($_POST['tax']); to this: $vendor = $_POST['vendor']; $date = $_POST['date']; $invoice = $_POST['invoice']; $total = $_POST['total']; $tax = $_POST['tax'];
  2. Are you trying to get the url and then redirect to that once a user has logged in? If so I am currently using this on my site and it works great. <?php session_start(); $url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; $uid = $_SESSION['uid']; if (!isset($uid)) { header("location:" . get_option('admin_url') . "login.php?redirect=".$url); exit(); die(); } ?>
  3. Aghh ok, this is normally the case with most php issues. Glad you got it working.
  4. Well there a few things bits that stood out. You have the following line of code: $fileExt = strtolower($fileExt); But you are not exactly checking the extension anywhere from what I have seen. You are also using a variable called type to select which type of image gets created but I can't see that defined anywhere in your code either. Why not check the file extension and then use that instead of type?
  5. Remove . $scale_ratio = $width / $height; if (($thumbWidth / $thumbHeight) > $scale_ratio) { $thumbWidth = $thumbHeight * $scale_ratio; } else { $thumbHeight = $thumbWidth / $scale_ratio; } and replace with $thumbWidth = 100; $thumbHeight = 50; Does that work?
  6. Try removing the following lines of code: $scale_ratio = $width / $height; if (($thumbWidth / $thumbHeight) > $scale_ratio) { $thumbWidth = $thumbHeight * $scale_ratio; } else { $thumbHeight = $thumbWidth / $scale_ratio; } and set the variables $thumbHeight and $thumbWidth with set values just for testing purposes. Does that work?
  7. I think you need to get the width and height of the old image. At the moment you are not defining the $width and $height variables. Above this line. imagecopyresampled($thumb, $oldImage, 0,0,0,0, $thumbWidth, $thumbHeight, $width, $height); add this. list($width,$height) = getimagesize($originalImage);
  8. Firstly PFMaBiSmAd, YOU ARE MY HERO! I can't believe that I hadn't noticed that before now. My error reporting had those weird american quotation marks. Once I had fixed this I was able to figure out that because I had moved the temporary file to the uploads directory I was longer able to use it in the imagecreatefromjpeg part of my script. The error I was getting was a failure to open stream because it was having trouble finding the image because it no longer existed. I changed the following lines of code: if($file_ext == "jpg" || $file_ext == "jpeg" ){ $src = imagecreatefromjpeg($file_tmp); } else if($file_ext == "png"){ $src = imagecreatefrompng($file_tmp); } else if($file_ext == "gif"){ $src = imagecreatefromgif($file_tmp); } to the following. if($file_ext == "jpg" || $file_ext == "jpeg" ){ $src = imagecreatefromjpeg($upload_dir . $file_new); } else if($file_ext == "png"){ $src = imagecreatefrompng($upload_dir . $file_new); } else if($file_ext == "gif"){ $src = imagecreatefromgif($upload_dir . $file_new); } The resized image is now being created properly. Thanks for everyones help.
  9. I have also tried using both imagecopyresized and imagecopyresampled. They both create a completely black thumbnail.
  10. Ok so I have found what the problem was that was causing the image not to resize properly. I had been defining the width and height like this. list($file_width,$file_height) = getimagesize($file_tmp); But in my following lines of code I was using the variables $width and $height instead of $file_width and $file_height. I changed the following three lines of code as follows: $file_height_new = ($height/$width) * $max_width; $tmp = imagecreatetruecolor($max_width,$file_height_new); imagecopyresampled($tmp,$src,0,0,0,0,$max_width,$file_height_new,$width,$height); to this $file_height_new = ($file_height/$file_width) * $max_width; $tmp = imagecreatetruecolor($max_width,$file_height_new); imagecopyresampled($tmp,$src,0,0,0,0,$max_width,$file_height_new,$file_width,$file_height); This has now resolved the resizing issue, however I have now ran into the same problem I had with my orginal script. The problem is that the thumbnail image that is being created is completely black. I don't know why but the original image isn't be copied properly. Does anyone have any ideas?
  11. Any reason why you have posted this topic twice? Please also put your code inside the code tags as it makes it easier for people to read. Thanks.
  12. That is a very valid point lordshoa, thank you for pointing that out. What method would you suggest that I use then? I also made sure that this wasn't causing the original issue of the image not being resized by changing the $file_height_new variable to a whole number. I am not trying to make images bigger, I only want to resize the image if it's width is larger than 570px. The reason for this is so that all uploaded images are in keeping with the websites design.
  13. If you don't have this in your code, I suggest you start by adding it immediately. ini_set('display_errors',1); error_reporting(E_ALL);
  14. Did you happen to notice anything else that stands out? It's always good to get some fresh eyes on your code. Thanks.
  15. I still don't think you need the ". before and ." after each variable either. But I maybe wrong.
  16. Surely what I'm calling the variable for imagecreatetruecolor should matter as long as i continue to use that variable?
  17. I have also tried creating a separate directory called thumbs to store the resized images by changing the following: imagejpeg($tmp,$upload_dir . $file_new,100); Which I changed to imagejpeg($tmp,"uploads/thumbs/" . $file_new,100); The resized images are not getting saved into the directory so therefor I'm assuming the problem is to do with the resizing part of the code but I can figure out what. From what I can see I am currently resizing the image using the following lines of code. imagecopyresampled($tmp,$src,0,0,0,0,$max_width,$file_height_new,$width,$height); I understand that I will need to create if statements based on the extension to recreate either jpgs, gifs and pngs using imagejpeg, imagegif and imagepng. But I have left them out for now until I get the resizing part working. While I am testing this current script i am only using jpgs. Can anyone spot something I ma missing?
  18. With most insert issues it's normally a spelling error with one or the variables, table names within the actual sql query. Double check everything is exactly how it should be. I don't think you need the following either. Your variables are currently like this ".$vendor."' but all you really need is this '$vendor' .
  19. Apologies, I had tried to modify the code as from my orginal which is posted below. I am still getting the same issue with that as well tho. The image is being saved in it's orginal state, and not being resized. I'd imagine it should be something quite simple, but I cannot for the life of me spot what the issue is. <?php ini_set(?display_errors?,1); error_reporting(E_ALL); $upload_dir = 'uploads/'; $max_width = 570; // Check if the upload and thumbs directories exist. // If they don't then we create them. if(!file_exists($upload_dir)) { if(mkdir($upload_dir)) { } else { exit_status($upload_dir . 'directory could not be created! Please check your folder permissions.'); } } $allowed_ext = array('jpg','jpeg', 'png','gif'); $unique_id = date("YmdHis"); $unique_id = $unique_id . rand(0,999999999); if(isset($_POST['upload_file'])){ $file_tmp = $_FILES['pic']['tmp_name']; $file_name = $_FILES['pic']['name']; $file_size = $_FILES['pic']['size']; $file_ext = get_extension($_FILES['pic']['name']); $file_new = $unique_id . "." . $file_ext; $createdby = $_SESSION["ufullname"]; if(in_array(get_extension($file_name),$allowed_ext)){ if($file_size < 2000000) { // Check the width of the uploaded image list($file_width,$file_height) = getimagesize($file_tmp); if($file_width > $max_width) { if(move_uploaded_file($file_tmp, $upload_dir . $file_new)){ connect(); $link = get_option('admin_url'); $sql = " INSERT into mediaT ( name, url, link, createdon, createdby ) VALUES ( '$file_name', '$upload_dir$file_new', '$link$upload_dir$file_new', NOW(), '$createdby' ) "; $result = mysql_query($sql); if($result) { if($file_ext == "jpg" || $file_ext == "jpeg" ){ $src = imagecreatefromjpeg($file_tmp); } else if($file_ext == "png"){ $src = imagecreatefrompng($file_tmp); } else if($file_ext == "gif"){ $src = imagecreatefromgif($file_tmp); } $file_height_new = ($height/$width) * $max_width; $tmp = imagecreatetruecolor($max_width,$file_height_new); imagecopyresampled($tmp,$src,0,0,0,0,$max_width,$file_height_new,$width,$height); imagejpeg($tmp,$upload_dir . $file_new,100); echo "Success! <i>$file_name has been added to your media library!</i>"; imagedestroy($src); imagedestroy($tmp); } else { echo "Error! <i>File couldn't be saved to the database.</i>"; } } else { echo "Error! <i>File couldn't be saved to $upload_dir.</i>"; } } else { if(move_uploaded_file($file_tmp, $upload_dir . $file_new)){ connect(); $link = get_option('admin_url'); $sql = " INSERT into mediaT ( name, url, link, createdon, createdby ) VALUES ( '$file_name', '$upload_dir$file_new', '$link$upload_dir$file_new', NOW(), '$createdby' ) "; $result = mysql_query($sql); if($result) { echo "Success! <i>$file_name has been added to your media library!</i>"; } else { echo "Error! <i>File couldn't be saved to the database.</i>"; } } else { echo "Error! <i>File couldn't be saved to $upload_dir.</i>"; } } } else { echo "Error! <i>Filesize is to large. Please upload a file under 2MB.</i>"; } } else { echo "Error! <i>Only the following file types are allowed ".implode(',',$allowed_ext).".</i>"; } } else { echo "Select a file to upload.<br /> <i>(With a maximum filesize of 2MB)</i>"; } function get_extension($file_name){ $ext = explode('.', $file_name); $ext = array_pop($ext); return strtolower($ext); } ?>
  20. Apologies for another thread about this, but i have completely re-written my previous code so it's no longer relevant to my previous post, hence why i am creating a new one. I am trying to create an image upload script which resizes the uploaded image to a set parameter and then saves it to an upload folder as well as the database. At the minute the image is being saved but not resized can anyone see what I am doing wrong?. <?php $upload_dir = 'uploads/'; $thumbs_dir = 'thumbs/'; $max_width = 570; // Check if the upload and thumbs directories exist. // If they don't then we create them. if(!file_exists($upload_dir)) { if(mkdir($upload_dir)) { if(!file_exists($upload_dir . $thumbs_dir)) { if(mkdir($upload_dir . $thumbs_dir)) { } else { exit_status($upload_dir . 'directory could not be created! Please check your folder permissions.'); } } } else { exit_status($upload_dir . 'directory could not be created! Please check your folder permissions.'); } } $allowed_ext = array('jpg','jpeg', 'png','gif'); $unique_id = date("YmdHis"); $unique_id = $unique_id . rand(0,999999999); if(isset($_POST['upload_file'])){ $file_tmp = $_FILES['pic']['tmp_name']; $file_name = $_FILES['pic']['name']; $file_size = $_FILES['pic']['size']; $file_ext = get_extension($_FILES['pic']['name']); $file_new = $unique_id . "." . $file_ext; $createdby = "Andrew"; if(in_array(get_extension($file_name),$allowed_ext)){ if($file_size < 2000000) { // Check the width of the uploaded image list($file_width,$file_height) = getimagesize($file_tmp); if($file_width > $max_width) { if($file_ext == "jpg" || $file_ext == "jpeg" ){ $src = imagecreatefromjpeg($file_tmp); } else if($file_ext == "png"){ $src = imagecreatefrompng($file_tmp); } else if($file_ext == "gif"){ $src = imagecreatefromgif($file_tmp); } $file_height_new = ($height/$width) * $max_width; $tmp = imagecreatetruecolor($max_width,$file_height_new); imagecopyresampled($tmp,$src,0,0,0,0,$max_width,$file_height_new,$width,$height); imagejpeg($tmp,$upload_dir . $file_new,100); if(move_uploaded_file($file_tmp, $upload_dir . $file_new)){ connect(); $link = get_option('admin_url'); $sql = " INSERT into mediaT ( name, url, link, createdon, createdby ) VALUES ( '$file_name', '$upload_dir$file_new', '$link$upload_dir$file_new', NOW(), '$createdby' ) "; $result = mysql_query($sql); if($result) { echo "Success! <i>$file_name has been added to your media library!</i>"; } else { echo "Error! <i>File couldn't be saved to the database.</i>"; } } else { echo "Error! <i>File couldn't be saved to $upload_dir.</i>"; } imagedestroy($src); imagedestroy($tmp); } else { if(move_uploaded_file($file_tmp, $upload_dir . $file_new)){ connect(); $link = get_option('admin_url'); $sql = " INSERT into mediaT ( name, url, link, createdon, createdby ) VALUES ( '$file_name', '$upload_dir$file_new', '$link$upload_dir$file_new', NOW(), '$createdby' ) "; $result = mysql_query($sql); if($result) { echo "Success! <i>$file_name has been added to your media library!</i>"; } else { echo "Error! <i>File couldn't be saved to the database.</i>"; } } else { echo "Error! <i>File couldn't be saved to $upload_dir.</i>"; } } } else { echo "Error! <i>Filesize is to large. Please upload a file under 2MB.</i>"; } } else { echo "Error! <i>Only the following file types are allowed ".implode(',',$allowed_ext).".</i>"; } } else { echo "Select a file to upload.<br /> <i>(With a maximum filesize of 2MB)</i>"; } function get_extension($file_name){ $ext = explode('.', $file_name); $ext = array_pop($ext); return strtolower($ext); } ?>
  21. I used this tutorial to get my head around how php works. Maybe you will find it as useful as I did. http://www.phpeasystep.com/phptu/29.html
  22. Does anyone have any idea what could be causing this?
  23. What you want do is that when ever I user logs in and checks the remember me function or whatever, you set a cookie called auth_code for example and save the value in a cookie as well as the database and associate it with that user. Then whenever a user accesses a protected page after their session has expires, you use a bit of code to check if the auth_code is present. If it is you check the database for its value and if it is present then log the user in and add a new value to the auth_code cookie and column in the database.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.