Jump to content

coolshrimp

Members
  • Posts

    73
  • Joined

  • Last visited

Contact Methods

  • Website URL
    http://coolshrimpmodz.com

Profile Information

  • Location
    Canada

coolshrimp's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. Thank you very much i got it working. http://demosites.com/Refugee/ now i work on comparing 2 arrays and not showing items if someone has already registered for an item.
  2. i found what was missing but when i print out array to a page it is blank.. <?php $categories = array(); $count = 0; foreach ($CSVArray as $row) { if ($count > 1 && !empty($row[0])) { $category = $row[0]; $item = $row[3]; $description = $row[4]; if(!isset($categories[$category])) { $categories[$category] = array(); } $categories[$category][] = array( 'Item' => $item, 'Description' => $description ); } } //List categories on screen print_r ($categories); ?>
  3. I get Parse error: syntax error, unexpected end of file
  4. I'm trying to auto populate a multidimensional box from a csv file. Example of drop down: Example Code for drop down: <select class="form-control" name="Items[]" multiple> <optgroup label="Catagory 1"></optgroup> <option value="1">Option 1</option> <option value="2">Option 2</option> <option value="3">Option 3</option> <option value="4">Option 4</option> <option value="5">Option 5</option> <option value="6">Option 6</option> <optgroup label="Catagory 2"></optgroup> <option value="1">Option 1</option> <option value="2">Option 2</option> <option value="3">Option 3</option> <option value="4">Option 4</option> <option value="5">Option 5</option> <option value="6">Option 6</option> </select> Here is what CSV looks like: Iv converted the CSV to an array then converted that array into multidimensional array and generated a drop box: <select class="form-control" name="Items[]" multiple> <?php $items = array(); $count = 0; foreach ($CSVArray as $row) { $count++; if ($count > 1 && $row[0] !== "") { array_push($items, array( "Catagory" => $row[0], "Item" => $row[3], "Description" => $row[4], )); } } $count = 0; foreach ($items as $row) { $count++; if ($count > 1 && $row[0] !== "") { array_push($items, array( "Catagory" => $row[0], "Item" => $row[3], "Description" => $row[3], )); echo "<optgroup label='{$row[Catagory]}'></optgroup>"; echo "<option value='$row[Item]'>{$row[Item]}({$row[Description]})</option>"; } } ?> </select> Now i have generated the dropdown but each catagory is listed multiple times on with each item: id like to Merge the duplicate category in the array but keeping the Items how can i do this? Bathroom Items Hand Towels Shower Curtain Wash Cloth Bedroom Items Alarm clock More More Current array: Array ( [0] => Array ( [Catagory] => Bathroom Items [Item] => bath mat [Description] => bath mat ) [1] => Array ( [Catagory] => Bathroom Items [Item] => bath towels [Description] => bath towels ) [2] => Array ( [Catagory] => Bathroom Items [Item] => hand towels [Description] => hand towels ) [3] => Array ( [Catagory] => Bathroom Items [Item] => rubber bath mat [Description] => rubber bath mat ) [4] => Array ( [Catagory] => Bathroom Items [Item] => shower curtain [Description] => shower curtain ) [5] => Array ( [Catagory] => Bedroom Items [Item] => alarm clock [Description] => alarm clock ) [6] => Array ( [Catagory] => Bedroom Items [Item] => bed sheets [Description] => bed sheets ) [7] => Array ( [Catagory] => Bedroom Items [Item] => bed sheets [Description] => bed sheets ) [8] => Array ( [Catagory] => Bedroom Items [Item] => bed sheets [Description] => bed sheets ) [9] => Array ( [Catagory] => Bedroom Items [Item] => bed sheets [Description] => bed sheets ) [10] => Array ( [Catagory] => Bedroom Items [Item] => blankets [Description] => blankets ) [11] => Array ( [Catagory] => Bedroom Items [Item] => blankets [Description] => blankets ) [12] => Array ( [Catagory] => Bedroom Items [Item] => blankets [Description] => blankets ) [13] => Array ( [Catagory] => Bedroom Items [Item] => blankets [Description] => blankets ) [14] => Array ( [Catagory] => Bedroom Items [Item] => dressers [Description] => dressers, bureaus ) [15] => Array ( [Catagory] => Bedroom Items [Item] => dressers [Description] => dressers, bureaus ) [16] => Array ( [Catagory] => Bedroom Items [Item] => dressers [Description] => dressers, bureaus ) [17] => Array ( [Catagory] => Bedroom Items [Item] => duvets / comforter [Description] => duvets / comforter ) [18] => Array ( [Catagory] => Bedroom Items [Item] => duvets / comforter [Description] => duvets / comforter ) [19] => Array ( [Catagory] => Bedroom Items [Item] => duvets / comforter [Description] => duvets / comforter ) [20] => Array ( [Catagory] => Bedroom Items [Item] => duvets / comforter [Description] => duvets / comforter ) [21] => Array ( [Catagory] => Bedroom Items [Item] => hamper [Description] => clothes hampers ) [22] => Array ( [Catagory] => Bedroom Items [Item] => hanger [Description] => clothes hangers ) [23] => Array ( [Catagory] => Bedroom Items [Item] => mattress covers [Description] => mattress covers ) [24] => Array ( [Catagory] => Bedroom Items [Item] => mirrors [Description] => mirrors ) [25] => Array ( [Catagory] => Bedroom Items [Item] => pillow cases [Description] => pillow cases ) [26] => Array ( [Catagory] => Bedroom Items [Item] => pillows [Description] => pillows ) [27] => Array ( [Catagory] => Bedroom Items [Item] => pillows [Description] => pillows ) [28] => Array ( [Catagory] => Bedroom Items [Item] => pillows [Description] => pillows ) [29] => Array ( [Catagory] => Bedroom Items [Item] => pillows [Description] => pillows ) [30] => Array ( [Catagory] => Bedroom Items [Item] => small garbage cans [Description] => small garbage cans ) )
  5. hey guys so i want to do this right no mistakes i need some help. I have one hosting account that i use to host multiple sites (Separate folders). id like to make it so if say a "website" in one folder got hacked they cannot access files in another websites folder. I was told open_basedir for each directory is what i need. Id like to protect each main folder listed in "HostedSites" as a separate site. (Website 1,2,3,4,5,) as well as my own main sites listed in public_html. (Shop, Forum, Demo) also is there a way to automatically set open_dir to any new site added into "HostedSites" folder. and id set the setting in a php.ini file and save in ect folder so it cannot be accessed or changed in-case of any vulnerabilities to my system correct? each site can be accessed 3 ways if that makes a difference. Addon Domain: Website_1.com Main Domain: mysite.com/HostedSites/Website_1 Subdomain: Website_1.mysite.com Here is sample of my directory structure. \ | \-ect | \-bin | \-php | \-mail | \-public_html | \-index.html | \-Shop | \-Forum | \-Demo | \-HostedSites | \-Website_1 | \-Website_2 | \-Website_3 | \-Website_4 | \-Website_5
  6. can i just do this use ajax to run script dosent seem to affect page at all and user will not know its running. it also appends to body the console log once it is done so i will know what went on. is this a proper use or any issues with this? <script type="application/javascript"> function loadimages(){ $.ajax({ type: "POST", url:"php/thumbnail/Thumb.php", success: function(html){ $('body').append(html); } }); } window.onload = function() { setTimeout(loadimages, 2000); }; </script> Seems to work. load page and watch console log for change: http://sale.coolshrimpmodz.com/index.html
  7. look over let me know if you see any possible issues. it seems to all work. Now how can i run this script without affecting users page load? will i just have to manually run it each time i make a change? or would a cron job be in order? if using cron would i do: curl http://sale.coolshrimpmodz.com/php/thumbnail/Thumb.php or wget http://sale.coolshrimpmodz.com/php/thumbnail/Thumb.php THE SCRIPT Thumb.php <?php /** * * @Created By Coolshrimp Modz */ /*error_reporting(E_ALL); ini_set('display_errors', 1);*/ include '../logConsole.php'; //CSV Reader Scripts $FileLocaton = $_SERVER['DOCUMENT_ROOT'] . '/php/CSVReader.php'; if (file_exists($FileLocaton)) { //Automatic Path include $FileLocaton; } else { //Backup Maual Path include '../CSVReader.php'; } //Set CSV Location $CSV = 'myfile.csv'; //CSV Converted To Array $CSVArray = csv_to_array($CSV); //Get List of Images from CSV File $logMessage = ""; // Set Folders To Save Images $saveLocationSmall = '../../images/thumbs/'; //Small Thumbs $saveLocationLarge = '../../images/thumbs/large/'; //Large Thumbs //Delete Old Tumbnails include 'RemoveOLD.php'; //Create New Thumbnails include 'Create.php'; //Send Results to browser console logConsole($logMessage); ?> RemoveOLD.php <?php /** * * @Created By Coolshrimp Modz */ $filesList = array(); //Scan Small Tumbs Directory For Files with .jpg extention $smallfilesArray = glob($saveLocationSmall . "*.jpg", GLOB_BRACE); //Scan Large Tumbs Directory For Files with .jpg extention $largefilesArray = glob($saveLocationLarge . "*.jpg", GLOB_BRACE); //Get list of files from Array to be compared against $count = 0; foreach ($CSVArray as $row) { $count++; if ($count > 1 && $row[1] !== "") { //Get FileID & Link URL from CSV $id = preg_replace("/[^a-zA-Z0-9]/", "", $row[1]); $fileNameSmall = $saveLocationSmall . $id . ".jpg"; $fileNameLarge = $saveLocationLarge . $id . ".jpg"; $filesListSmall[] = $fileNameSmall; $filesListLarge[] = $fileNameLarge; } } //Compare Arrays for diffrences $resultSmall = array_diff($smallfilesArray, $filesListSmall); $resultLarge = array_diff($largefilesArray , $filesListLarge); //List Of Small Files Not On List To Be Removed $count = 0; foreach ($resultSmall as $row) { $count++; if ($count > 1) { //Get File Name $logMessage .= "Small Thumb To Be Removed " . $row . "\\n"; //Remove The Images if(file_exists($row)) { unlink($row); //delete file if(file_exists($row)) { $logMessage .= "Small Thumb Could Not Be Deleted " . $row . "\\n"; } else { $logMessage .= "Small Thumb Deleted " . $row . "\\n"; } } } } //List Of Large Files Not On List To Be Removed $count = 0; foreach ($resultLarge as $row) { $count++; if ($count > 1) { //Get File Name $logMessage .= "Large Thumb To Be Removed " . $row . "\\n"; //Remove The Images if(file_exists($row)) { unlink($row); //delete file if(file_exists($row)) { $logMessage .= "Large Thumb Could Not Be Deleted " . $row . "\\n"; } else { $logMessage .= "Large Thumb Deleted " . $row . "\\n"; } } } } ?> Create.php <?php /** * * @Created By Coolshrimp Modz */ include 'CreateThumbSave.php'; $count = 0; foreach ($CSVArray as $row) { $count++; if ($count > 1 && $row[1] !== "") { //Get FileID & Link URL from CSV $id = preg_replace("/[^a-zA-Z0-9]/", "", $row[1]); $file = $row[8]; $SaveAsSmall = $saveLocationSmall . $id . ".jpg"; $SaveAsLarge = $saveLocationLarge . $id . ".jpg"; if (!file_exists($SaveAsSmall)) { $logMessage .= "Missing Small Thumb for " . $id . "\\n"; //Create Tumbs Small And Save $maxw = 200; $maxh = 200; $logMessage .= CreateThumb($file, $maxw, $maxh, $SaveAsSmall); } else { $logMessage .= "Found Small Thumb for " . $id . "\\n"; } if (!file_exists($SaveAsLarge)) { $logMessage .= "Missing Large Thumb for " . $id . "\\n"; //Create Tumbs Large And Save $maxw = 400; $maxh = 400; $logMessage .= CreateThumb($file, $maxw, $maxh, $SaveAsLarge); } else { $logMessage .= "Found Large Thumb for " . $id . "\\n"; } } } ?> CreateTumbsSave.php <?php /** * * @Created By Coolshrimp Modz */ function CreateThumb($file, $maxw, $maxh, $id) { $sImagePath = $file; $iMaxWidth = (int)$maxw; $iMaxHeight = (int)$maxh; if ($iMaxWidth && $iMaxHeight) $sType = 'scale'; $img = NULL; $sExtension = strtolower(end(explode('.', $sImagePath))); if ($sExtension == 'jpg' || $sExtension == 'jpeg') { if (!$img = @imagecreatefromjpeg($sImagePath)) { return "Cannot create new JPEG image for " . $id . "\\n"; } } else if ($sExtension == 'png') { if (!$img = @imagecreatefrompng($sImagePath)) { return "Cannot create new PNG image for " . $id . "\\n"; } } else if ($sExtension == 'gif') { if (!$img = @imagecreatefromgif($sImagePath)) { return "Cannot create new GIF image for " . $id . "\\n"; } } else { if (!$img = @imagecreatefromjpeg($sImagePath)) { return "Cannot create new image for " . $id . "\\n"; } } if ($img) { $iOrigWidth = imagesx($img); $iOrigHeight = imagesy($img); if ($sType == 'scale') { // Get scale ratio $fScale = min($iMaxWidth/$iOrigWidth, $iMaxHeight/$iOrigHeight); if ($fScale < 1) { $iNewWidth = floor($fScale*$iOrigWidth); $iNewHeight = floor($fScale*$iOrigHeight); $tmpimg = imagecreatetruecolor($iNewWidth, $iNewHeight); imagecopyresampled($tmpimg, $img, 0, 0, 0, 0, $iNewWidth, $iNewHeight, $iOrigWidth, $iOrigHeight); imagedestroy($img); $img = $tmpimg; } } imagejpeg($img, $id); return "Thumb Created And Saved To " . $id . "\\n"; } } ?>
  8. Check it out. Here is page that will show you what has images and what does not. http://sale.coolshrimpmodz.com/php/thumbnail/check.html Here is Script that creates or removes thumbs from folder, Page is blank but it prints out log to browser console. http://sale.coolshrimpmodz.com/php/thumbnail/Thumb.php
  9. Thanks so far for your guys help. I'm creating a script for all to use that will compare a list of files to directory of files and it will create or delete thumbs. will post soon will need suggestions on how to run this each time person visits page without making them wait if possible.
  10. think i got it changed to $img = @imagecreatefromjpeg($sImagePath) or print_r ("Cannot create new JPEG image<br>");
  11. on my script above in the function "CreateThumb" $img = @imagecreatefromjpeg($sImagePath) or die("Cannot create new JPEG image"); if it cant create image it will Die and echo error message. how can i make it end the function but continue the script. Die seems to stop whole script on error. i want it to continue onto the next image.
  12. page is down to 3sec to render at 1.4 MB http://tools.pingdom.com/fpt/#!/54o5D/http://sale.coolshrimpmodz.com/index_test.html
  13. ok ill have to lear how this whole ajax thing works. as for my script above see any issues? it seems to work
  14. iv got it working now how can i show each echo in script as it runs and not all at once when php is finished. Here is code that is working: Reads from my CSV, check is image tumbs aready exist, if not then creates a small thumb from (Image URL) and saves with (ID) iv specified in a column, then creates a big thumb and saves the same way. <?php echo "Creating Thumbnails<br><br>"; //CSV Reader Scripts $FileLocaton = $_SERVER['DOCUMENT_ROOT'] . '/php/CSVReader.php'; if (file_exists($FileLocaton)) { //Automatic Path include $FileLocaton; } else { //Backup Maual Path include 'php/CSVReader.php'; } //Set CSV Location $CSV = 'CSVlinks.csv'; //CSV Converted To Array $CSVArray = csv_to_array($CSV); $count = 0; foreach ($CSVArray as $row) { $count++; if ($count > 1 && $row[1] !== "") { //Get FileID & Link URL from CSV $id = preg_replace("/[^a-zA-Z0-9]/", "", $row[1]); $file = $row[8]; $saveto = "images/thumbs/"; $SaveAsSmall = $saveto . $id . ".jpg"; $SaveAsLarge = $saveto . "large/" . $id . ".jpg"; Echo "Checking for Large Thumb ({$id}.jpg)<br>"; if (!file_exists($SaveAsSmall)) { //Create Tumbs Small And Save $maxw = 200; $maxh = 200; CreateThumb($file, $maxw, $maxh, $SaveAsSmall); Echo "Created Small Thumb for ({$id})<br>"; } else { Echo "Found Small Thumb for ({$id})<br>"; } Echo "Checking for Small Thumb ({$id}.jpg)<br>"; if (!file_exists($SaveAsLarge)) { //Create Tumbs Small And Save $maxw = 400; $maxh = 400; CreateThumb($file, $maxw, $maxh, $SaveAsLarge); Echo "Created Large Thumb for ({$id})<br>"; } else { Echo "Found Large Thumb for ({$id})<br>"; } echo "<br><br>"; } } function CreateThumb($file, $maxw, $maxh, $id) { $sImagePath = $file; $iMaxWidth = (int)$maxw; $iMaxHeight = (int)$maxh; if ($iMaxWidth && $iMaxHeight) $sType = 'scale'; $img = NULL; $sExtension = strtolower(end(explode('.', $sImagePath))); if ($sExtension == 'jpg' || $sExtension == 'jpeg') { $img = @imagecreatefromjpeg($sImagePath) or die("Cannot create new JPEG image"); } else if ($sExtension == 'png') { $img = @imagecreatefrompng($sImagePath) or die("Cannot create new PNG image"); } else if ($sExtension == 'gif') { $img = @imagecreatefromgif($sImagePath) or die("Cannot create new GIF image"); } if ($img) { $iOrigWidth = imagesx($img); $iOrigHeight = imagesy($img); if ($sType == 'scale') { // Get scale ratio $fScale = min($iMaxWidth/$iOrigWidth, $iMaxHeight/$iOrigHeight); if ($fScale < 1) { $iNewWidth = floor($fScale*$iOrigWidth); $iNewHeight = floor($fScale*$iOrigHeight); $tmpimg = imagecreatetruecolor($iNewWidth, $iNewHeight); imagecopyresampled($tmpimg, $img, 0, 0, 0, 0, $iNewWidth, $iNewHeight, $iOrigWidth, $iOrigHeight); imagedestroy($img); $img = $tmpimg; } } imagejpeg($img, $id); echo "Saved as {$id}<br><br>"; } } ?>
  15. this on the right track? <?php //CSV Reader Scripts $FileLocaton = $_SERVER['DOCUMENT_ROOT'] . '/php/CSVReader.php'; if (file_exists($FileLocaton)) { //Automatic Path include $FileLocaton; } else { //Backup Maual Path include 'php/CSVReader.php'; } //Set CSV Location $CSV = 'csvlist.csv'; //CSV Converted To Array $CSVArray = csv_to_array($CSV); $count = 0; foreach ($CSVArray as $row) { $count++; if ($count > 1 && $row[1] !== "") { //Get FileID & Link URL from CSV $id = preg_replace("/[^a-zA-Z0-9]/", "", $row[1]); $file = $row[8]; //set thumb max dimentions $maxw = 200; $maxh = 200; //Create Tumbs CreateThumb($file, $maxw, $maxh); //Save Tumbs imagejpeg($img, "images/thumbs/{$id}" ); } } function CreateThumb($file, $maxw, $maxh) { $sImagePath = $file; $iMaxWidth = (int)$maxw; $iMaxHeight = (int)$maxh; if ($iMaxWidth && $iMaxHeight) $sType = 'scale'; $img = NULL; $sExtension = strtolower(end(explode('.', $sImagePath))); if ($sExtension == 'jpg' || $sExtension == 'jpeg') { $img = @imagecreatefromjpeg($sImagePath) or die("Cannot create new JPEG image"); } else if ($sExtension == 'png') { $img = @imagecreatefrompng($sImagePath) or die("Cannot create new PNG image"); } else if ($sExtension == 'gif') { $img = @imagecreatefromgif($sImagePath) or die("Cannot create new GIF image"); } if ($img) { $iOrigWidth = imagesx($img); $iOrigHeight = imagesy($img); if ($sType == 'scale') { // Get scale ratio $fScale = min($iMaxWidth/$iOrigWidth, $iMaxHeight/$iOrigHeight); if ($fScale < 1) { $iNewWidth = floor($fScale*$iOrigWidth); $iNewHeight = floor($fScale*$iOrigHeight); $tmpimg = imagecreatetruecolor($iNewWidth, $iNewHeight); imagecopyresampled($tmpimg, $img, 0, 0, 0, 0, $iNewWidth, $iNewHeight, $iOrigWidth, $iOrigHeight); imagedestroy($img); $img = $tmpimg; } } } } ?>
×
×
  • Create New...