Jump to content

imgrooot

Members
  • Posts

    383
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by imgrooot

  1. I do get 500 errors if I add invalid code in .htaccess. So it does work. It can't just be the live host server because I have the same issue on localhost. Weird thing is, I have another websites with the exact same .htaccess file on localhost and they seem to work fine.
  2. This is so strange. I have this bit of code that removes the .php extension from pages so that I can visit any page without typing .php at the end. RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*)$ $1.php [L] The above code has always worked for me before. But for some reason today it stopped working on localhost and the live server(ipage hosting). Do you know why that might be?
  3. Yes that's exactly what I was asking. I now understand that is not possible.
  4. Question 1. I have a form and on submit it redirects to another site. Is it possible to open that site in a new tab instead of the same page? I have tried this js code and it doesn't seem to work. if() { $get_url = 'https://www.google.ca/'; ?> <script> window.open('<?php echo $get_url; ?>','_blank'); </script> <?php } Question 2. Is it possible to have a extend popup to another site using a unique link? Take the above google link for example. Is it possible to add new code at the end of that link url which will show a popup window or something on that google page if only visited through that link?
  5. I do see the option for 5.6x but it says it's currently in BETA stage. Is it wise to use it? Btw, I am using bluehost web hosting.
  6. Yes it's the “namespace {”. And yes you're correct. The server was running older PHP version. I switched it to PHP 5.4 and i no longer get that error. Thanks for clearing it up.
  7. I am using this https://github.com/ircmaxell/password_compat I have no problem using it on a local server. But as soon as I test it on a live server, it gives me an error like this. Parse error: syntax error, unexpected '{' in /home/public_html/sub/snippets/password.php on line 19 The error is on the same line as the beginning of the code in that library. Why is this happening?
  8. Yep the above works if I have the ".show-details" div as a child of parent div ".product" like this. <div class="product"> <div class="product-title"> <?php echo $get_record_title; ?> </div> <div class="product-price"> <?php echo $get_record_price; ?> </div> <div class="show-details"> <?php echo $get_record_details; ?> </div> </div>
  9. So something like this? <script> $(document).ready(function() { $(".product").mouseover(function(){ $(".show-details").css("display", "block"); }); $(".product").mouseout(function(){ $(".show-details").css("display", "none"); }); }); </script>
  10. The thing is, if I have 10 records on a page and I use the above javascript code to show the hidden div, it will show the div for all 10 records at the same time. I don't want that. I just want it show a div for each unique record one at a time as I hover my mouse over them. So that is why I am asking what the javascript code will look like to make that work?
  11. Here's what I'm trying to do. I retrieve results using php foreach loop. Within that loop results, I want to show a div(.show-details) on mouse over only. How do I do that? This is my code so far. <style> .show-details { display: none; } </style> $get_records = $db->prepare("SELECT * FROM records WHERE record_id = :record_id"); $get_records->bindParam(':record_id', $record_id); $get_records->execute(); $result_records = $get_records->fetchAll(PDO::FETCH_ASSOC); if(count($result_records) > 0){ foreach($result_records as $row) { $get_record_title = $row['record_title']; $get_record_details = $row['record_details']; $get_record_price = $row['record_price']; ?> <div class="product"> <div class="product-title"> <?php echo $get_record_title; ?> </div> <div class="product-price"> <?php echo $get_record_price; ?> </div> </div> <div class="show-details"> <?php echo $get_record_details; ?> </div> <?php } } else { echo 'no results.'; } <script> $(document).ready(function() { $(".product").mouseover(function(){ $(".show-details").css("display", "block"); }); }); </script>
  12. Say I have this loop. foreach($record as $row) { <div class="hello">Hello World!</div> } I want to loop through and add a letter alongside the "Hello World!" above. To do that, I found this code. $azRange = range('A', 'Z'); foreach ($azRange as $letter) { print("$letter\n"); } How can I combine the two loops so that I get a result like this? A Hello World! B Hello World! C Hello World! D Hello World! E Hello World! F Hello World!
  13. I am trying out a new script that lets me resize an image before uploading. It is based on this script. http://www.w3bees.com/2013/03/resize-image-while-upload-using-php.html Basically what happens is, it resizes and makes 3 thumbnails and puts them in their relative folder. That works. The part that's giving me the problem is when inserting it into the database. Error says the "image_path" cannot be null. Since it's creating an array of 3 different thumbnails, should I create 2 more fields in the database tabel to account for that? If so, how would I insert the 3 different thumbnail paths into the query? What would it look like? Below is my code. <?php $db_userid = intval($row['user_id']); $get_item_id = intval($row['item_id']); // settings $max_file_size = 5242880; // 5mb $valid_exts = array('jpeg', 'jpg', 'png', 'gif'); // thumbnail sizes $sizes = array(100 => 100, 150 => 150, 250 => 250); // dir paths $target_dir = 'images/'.$db_userid.'/items/'.$get_item_id.'/'; if ($_SERVER['REQUEST_METHOD'] == 'POST' AND isset($_FILES['image'])) { if(!empty($_FILES['image']['name'])) { if($_FILES['image']['size'] < $max_file_size ){ // get file extension $ext = strtolower(pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION)); if(in_array($ext, $valid_exts)) { function resize($width, $height){ global $db_userid; global $get_item_id; /* Get original image x y*/ list($w, $h) = getimagesize($_FILES['image']['tmp_name']); /* calculate new image size with ratio */ $ratio = max($width/$w, $height/$h); $h = ceil($height / $ratio); $x = ($w - $width / $ratio) / 2; $w = ceil($width / $ratio); /* new file name */ $path = 'images/'.$db_userid.'/items/'.$get_item_id.'/'.$width.'x'.$height.'_'.$_FILES['image']['name']; /* read binary data from image file */ $imgString = file_get_contents($_FILES['image']['tmp_name']); /* create image from string */ $image = imagecreatefromstring($imgString); $tmp = imagecreatetruecolor($width, $height); imagecopyresampled($tmp, $image, 0, 0, $x, 0, $width, $height, $w, $h); /* Save image */ switch ($_FILES['image']['type']) { case 'image/jpeg': imagejpeg($tmp, $path, 100); break; case 'image/png': imagepng($tmp, $path, 0); break; case 'image/gif': imagegif($tmp, $path); break; default: exit; break; } return $path; /* cleanup memory */ imagedestroy($image); imagedestroy($tmp); } /* resize image */ foreach($sizes as $w => $h) { if(!is_dir($target_dir)){ mkdir($target_dir, 0775, true); } $files[] = resize($w, $h); } $insert_image = $db->prepare("INSERT INTO images(user_id, item_id, image_path, date_added) VALUES(:user_id, :item_id, :image_path, :date_added)"); $insert_image->bindParam(':user_id', $db_userid); $insert_image->bindParam(':item_id', $get_item_id); $insert_image->bindParam(':image_path', $path); $insert_image->bindParam(':date_added', $item_date_added); if(!$insert_image->execute()) { $errors[] = 'There was a problem uploading the image!'; } else { if(empty($errors)) { $db->commit(); $success = 'Your item has been saved.'; } else { $db->rollBack(); } } } else { $errors[] = 'Unsupported file'; } } else{ $errors[] = 'Please upload image smaller than 5mb'; } } else { $errors[] = 'An image is required!'; } }
  14. Basically the "title" and "details" inputs are for showing text on a page. I need CKEditor for the "details" input so that the user can modify the text. That seo_description input is suppose to have the same value as the "details" input. So instead of making the user write the same text again in the seo_page_description textarea, I am having it so that it automatically adds to it from the "details" input. And since seo_page_description is only going to showing in the meta details in the header, I only need it in plain text. One thing I noticed. The textarea that has the CKeditor; it inserts the text(with tags) into the MySql database fine. I can also retrive it from the database fine. It includes all the html tags. However the text is not styled by default. I have to style the tags with css for the text to appear as the user has intended in the Ckeditor. Is this normal?
  15. Yes since it's the meta title and description, I only require the plain text. Your method works perfectly now. Thank you so much!
  16. Perfect! That's what I was looking for. One minor thing. Is it possible to remove/hide the "<p>" tag that shows up in the seo_page_description textarea?
  17. So can you show me the reverse of what you did? Like switch the "details" with "seo_page_description"?
  18. That works, but I think my original question might have been a bit misunderstood. I already have the ckeditor in the details textarea. I don't have the ckeditor in the seo description textarea and I don't need one either. Your example works, but it's the opposite of what I am looking to do.
  19. Can you please show me how I would use the "setData method" within my code above?
  20. Oh I see why it wasn't working. I am also using "ckeditor(http://ckeditor.com/)" in the textarea field. Once I removed it, it worked. Though I really need to use that editor. How can I make it work with having that editor as well?
  21. You know when you type text into a form input and it automatically types the same text in another div? Well I am trying to do the same thing but instead show the same text value from the div 1 to div 2. Here is my code. It works with the input text field but not with the textarea. Can you tell me why? <input type="text" name="title" id="title" value="" maxlength="55" /> <textarea name="details" id="details" value="" maxlength="160" ></textarea> <!-- Values show up in these inputs --> <input type="text" name="seo_page_title" id="seo_page_title" value="" maxlength="55" /> <textarea name="seo_page_description" id="seo_page_description" maxlength="160" ></textarea> <script> $('#title').on("input", function() { var dInput = this.value; console.log(dInput); $('#seo_page_title').val(dInput); }); $('#details').on("input", function() { var dInput = this.value; console.log(dInput); $('#seo_page_description').val(dInput); }); </script>
  22. Your comment made me think of something. So I added this code and now it works. if(!is_dir($target_dir)){ mkdir($target_dir, 0775, true); }
  23. I am using a simple image upload. http://www.w3schools.com/php/php_file_upload.asp It gives me 2 errors like this. Warning: move_uploaded_file(C:/xampp/htdocs/home/upload/images/grandpix 2.jpg): failed to open stream: No such file or directory in C:\xampp\htdocs\home\upload\post.php on line 174 Warning: move_uploaded_file(): Unable to move 'C:\xampp\tmp\phpF915.tmp' to 'C:/xampp/htdocs/home/upload/images/grandpix 2.jpg' in C:\xampp\htdocs\home\upload\post.php on line 174 This is my code. Post.php . I see that it's the "$target_dir" issue. How can I fix it? if(isset($_FILES['fileToUpload'])){ if(!empty($_FILES['fileToUpload']['name'])) { $target_dir = $_SERVER['DOCUMENT_ROOT'].'/home/upload/images/'; $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $uploadOk = 1; $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); if($check !== false) { $uploadOk = 1; } else { $errors[] = 'File is not an image.'; $uploadOk = 0; } // Check if file already exists if (file_exists($target_file)) { $errors[] = 'Sorry, file already exists.'; $uploadOk = 0; } // Check file size if ($_FILES["fileToUpload"]["size"] > 500000) { $errors[] = 'Sorry, your file is too large.'; $uploadOk = 0; } // Allow certain file formats if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) { $errors[] = 'Sorry, only JPG, JPEG, PNG & GIF files are allowed.'; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { $errors[] = 'Sorry, your file was not uploaded.'; // if everything is ok, try to upload file } else { if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded."; } else { $errors[] = 'Sorry, there was an error uploading your file.'; } } $insert_image = $db->prepare("INSERT INTO images(user_id, item_id, image_path, date_added) VALUES(:user_id, :item_id, :image_path, :date_added)"); $insert_image->bindParam(':user_id', $userid); $insert_image->bindParam(':item_id', $item_id); $insert_image->bindParam(':image_path', $target_file); $insert_image->bindParam(':date_added', $date_added); if(!$insert_image->execute()) { $errors[] = 'There was a problem uploading the image!'; } else { if(empty($errors)) { $db->commit(); $success = 'Your post has been saved.'; } else { $db->rollBack(); } } } else { $errors[] = 'An image is required!'; } }
×
×
  • 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.