PageRenderTime 63ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/inc/amfphp/administration/swatchuploaderscript.php

https://github.com/EmranAhmed/wp-easycart
PHP | 118 lines | 42 code | 46 blank | 30 comment | 2 complexity | 7bab5b9fad7ee5fbd059f033d661989e MD5 | raw file
  1. <?php
  2. /*
  3. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  5. //All Code and Design is copyrighted by Level Four Development, llc
  6. //
  7. //Level Four Development, LLC provides this code "as is" without warranty of any kind, either express or implied,
  8. //including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
  9. //
  10. //Only licensed users may use this code and storfront for live purposes. All other use is prohibited and may be
  11. //subject to copyright violation laws. If you have any questions regarding proper use of this code, please
  12. //contact Level Four Development, llc and EasyCart prior to use.
  13. //
  14. //All use of this storefront is subject to our terms of agreement found on Level Four Development, llc's website.
  15. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  16. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  17. */
  18. //load our connection settings
  19. require_once('../../../../../../wp-config.php');
  20. //set our connection variables
  21. $dbhost = DB_HOST;
  22. $dbname = DB_NAME;
  23. $dbuser = DB_USER;
  24. $dbpass = DB_PASSWORD;
  25. //make a connection to our database
  26. mysql_connect($dbhost, $dbuser, $dbpass);
  27. mysql_select_db ($dbname);
  28. $settings_sql = "SELECT max_width, max_height FROM ec_setting";
  29. $settings_result = mysql_query($settings_sql);
  30. $settings_row = mysql_fetch_assoc($settings_result);
  31. //Flash Variables
  32. $date = $_POST['datemd5'];
  33. $requestID = $_POST['reqID'];
  34. $optionitemid = $_POST['optionitemid'];
  35. $maxwidth = $settings_row['max_width'];
  36. $maxheight = $settings_row['max_height'];
  37. $imagequality = $_POST['imagequality'];//set this between 0 and $imagequality for .jpg quality resizing
  38. //Get User Information
  39. $usersqlquery = sprintf("SELECT ec_user.*, ec_role.admin_access FROM ec_user LEFT JOIN ec_role ON (ec_user.user_level = ec_role.role_label) WHERE ec_user.password = '%s' AND (ec_user.user_level = 'admin' OR ec_role.admin_access = 1)", mysql_real_escape_string($requestID));
  40. $userresult = mysql_query($usersqlquery);
  41. $users = mysql_fetch_assoc($userresult);
  42. if ($users || is_user_logged_in()) {
  43. //Flash File Data
  44. $filename = $_FILES['Filedata']['name'];
  45. $filetmpname = $_FILES['Filedata']['tmp_name'];
  46. $fileType = $_FILES["Filedata"]["type"];
  47. $fileSizeMB = ($_FILES["Filedata"]["size"] / 1024 / 1000);
  48. //$explodedfilename = explode(".", $filename);
  49. //$nameoffile = $explodedfilename[0];
  50. //$fileextension = $explodedfilename[1];
  51. $explodedfilename = pathinfo($filename);
  52. $nameoffile = $explodedfilename['filename'];
  53. $fileextension = $explodedfilename['extension'];
  54. include("resizer.php");
  55. // Place file on server, into the images folder
  56. move_uploaded_file($_FILES['Filedata']['tmp_name'], "../../../products/swatches/".$nameoffile."_".$date.".".$fileextension);
  57. copy( "../../../products/swatches/".$nameoffile."_".$date.".".$fileextension, "../../../../wp-easycart-data/products/swatches/".$nameoffile."_".$date.".".$fileextension);
  58. //resize original max image
  59. $resizeObj = new resizer("../../../products/swatches/".$nameoffile."_".$date.".".$fileextension);
  60. $resizeObj->resize($maxwidth, $maxheight, "../../../products/swatches/".$nameoffile."_".$date.".".$fileextension, $imagequality );
  61. $resizeObj = new resizer("../../../../wp-easycart-data/products/swatches/".$nameoffile."_".$date.".".$fileextension);
  62. $resizeObj->resize($maxwidth, $maxheight, "../../../../wp-easycart-data/products/swatches/".$nameoffile."_".$date.".".$fileextension, $imagequality );
  63. //if we are updating, then update the db field, inserting happens later
  64. //Create SQL Query
  65. $sqlfilename = $nameoffile . '_' . $date . '.' .$fileextension;
  66. $sql = sprintf("Update ec_optionitem SET ec_optionitem.optionitem_icon = '%s' WHERE ec_optionitem.optionitem_id = '%s'",
  67. mysql_real_escape_string($sqlfilename),
  68. mysql_real_escape_string($optionitemid));
  69. //Run query on database;
  70. mysql_query($sql);
  71. }
  72. ?>