Jump to content

JayStabins

Members
  • Posts

    12
  • Joined

  • Last visited

Everything posted by JayStabins

  1. Much better than the apache documentation. http://httpd.apache.org/docs/current/mod/mod_rewrite.html While reading this I was wondering about the difference between the mod_rewrite # Generic 404 to show the "custom_404.html" page # If the requested page is not a file or directory # Silent Redirect: the user's URL bar is unchanged. RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* custom_404.html [L] and the simple ErrorDocument 404 /404error.php Thanks again for the help!
  2. Does anyone have a resource to help explain permalinks? Basically I am wondering how to implement something on the blog I am starting to write. Take this link for example.... http://cristinabarkerjones.wordpress.com/2013/07/18/10-reasons-you-should-get-a-dog/ (this is just some random blog I pulled up, no plug or try to get hits here) I think we can agree there is no html/php page sitting on a server in a folder /2013/07/18/ with a page name of 10-reasons-you-should-get-a-dog. Instead there is a server that s going to render this page who's data is sitting in a database. My question is how do you implement something like this. I know it is an involved process, just looking if someone has a resource on how this is implemented or wants to give me a quick overview that would be great! Thanks!
  3. Here is a sample of what I use for a simple email send $emailServer = 'me@myDomain.com'; $emailFrom = 'myName'; $to = "\"" . $CleanMessage->getSender() . "\" <" . $CleanMessage->getEmail() . ">"; $message = $CleanMessage->getMessage(); // To send HTML mail, the Content-type header must be set $headers = "From: \"" . $emailFrom . "\" <" . $emailServer . ">\n"; $headers .= "MIME-Version: 1.0" . "\n"; $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n"; if(mail($to, $CleanMessage->getTitle(), $message, $headers)){ //message sent; }else { die('Message not sent die mother fucker!'); } Not complete and I have my message in a class objec called $CleanMessage, this has all my prepossessing done and has just been inserted into a MySql database but you get the point...
  4. I guess the best advice I would give is build a simple 3-4 page website and see where the code duplication exists. From there you will see where OOP really comes into play. "Anywhere" you see the same code repeated, make a function. "Anywhere" you see multiple functions repeat themselves, make a class. PHP manual is your friend. http://php.net/manual/en/language.oop5.php what does your index.php look like right now?
  5. ^this I cannot like or otherwise +1 mac_gyver but the fact of the matter is you really need a production server or setup some "advanced" setup to do this from your local machine. If you have a web host try it on their server, if not it is probably a setting in your php.ini. A lot of servers require you to have the "From" header assigned to one of their servers to help prevent spam.
  6. <?php is always a good start Kidding obviously but why not show what you have so far and see if we can't figure something out.
  7. I know that this has probably come up a lot but a quick search didn't give me the answer I am looking for.. haha. Anyway, I want to know what is really needed to do to user input while dealing with my database. I know that using straight sql is a no go and wouldn't. Back years ago I worked for a small marketing company using MSSql and we handled user input way different than is happening now and just want to make sure I am not doing anything stupid. From everything I am reading as long as I am using prepared statements in PDO I should really have no problem with SQL ingection. A good site I got a kick out of while doing my research is here http://bobby-tables.com/php.html So as long as I am doing prepared named queries I should have no problem with SQL injection issues? $dbh = new PDO('mysql:dbname=testdb;host=127.0.0.1', $user, $password); $stmt = $dbh->prepare('UPDATE people SET name = :new_name WHERE id = :id'); $stmt->execute( array('new_name' => $name, 'id' => $id) ); While this would be great news I can't believe it. Now I know that this does not protect against DISPLAYING information from the database which is a separate issue, using something like htmlspecialchars should always be used when displaying based on your medium. So what do you do when dealing with user input? If you are using prepared statements do you bother doing any type of check? If so, what are we doing with PDO data? If you are still using something what are we doing? if not I am just as happy and would love to hear if so because it would really make my life a lot eaiser!! Thanks in advance!
  8. You nailed it, once I use the move_uploaded_file function I lose the file from the $_POST, so I passed the file location instead when calling the function again. I put some checks in the function to ensure that the file location is being used properly and also the switch statement is now nested (because I am using the function for one purpose) and now it works flawlessly. Here it he script for anyone that may want to use it to create a thumb and an image from one uploaded file. Cheers! function imageUpload($file, $user, $isThumb = FALSE) { // create thumbnail or save picture if ($isThumb) { $userDirectory = $_SESSION ['member_id'] . "/images/thumbs"; $max = 100; } else { $userDirectory = $_SESSION ['member_id'] . "/images"; $max = 800; } $directorySelf = $_SERVER ['PHP_SELF']; $upload_directory = $_SERVER ['DOCUMENT_ROOT'] . $directorySelf . "$userDirectory/"; $saveto = "$upload_directory" . time () . ".jpg"; if (! makeDir ( "$upload_directory" )) throw new Exception ( 'Error creating location on server, please try again...' ); if ($isThumb) { echo "About to try and copy " . $file . " to " . $saveto; copy ( $file, $saveto ); $src = imagecreatefromjpeg ( $saveto ); } else { if (! move_uploaded_file ( $file ['image'] ['tmp_name'], $saveto )) throw new Exception ( 'Error copying image to server, please try again...' ); switch ($file ['image'] ['type']) { case 'image/gif' : $src = imagecreatefromgif ( $saveto ); break; case 'image/jpeg' : case 'image/pjpeg' : $src = imagecreatefromjpeg ( $saveto ); break; case 'image/png' : $src = imagecreatefrompng ( $saveto ); break; default : // invalid image type throw new Exception ( 'Error, invalid file type. Please upload only (.gif, .png or .jpg)' ); break; } } list ( $w, $h ) = getimagesize ( $saveto ); $tw = $w; $th = $h; if ($w > $h && $max < $h) { $th = $max / $w * $h; $tw = $max; } elseif ($h > $w && $max < $h) { $tw = $max / $h * $w; $th = $max; } elseif ($max < $w) { $tw = $th = $max; } try { $tmp = imagecreatetruecolor ( $tw, $th ); imagecopyresampled ( $tmp, $src, 0, 0, 0, 0, $tw, $th, $w, $h ); imageconvolution ( $tmp, array ( array ( - 1, - 1, - 1 ), array ( - 1, 16, - 1 ), array ( - 1, - 1, - 1 ) ), 8, 0 ); try { imagejpeg ( $tmp, $saveto ); } catch ( Exception $e ) { throw new Exception ( 'Error with function imagejpeg() ' . $e->getMessage () ); } } catch ( Exception $e ) { throw new Exception ( 'Error Code: ' . $e->getCode () ); } try { if (! $isThumb) { echo "About to create thumbnail for image<br />"; // create thumbnail for image $thumbLocation = imageUpload ( $saveto, $user, TRUE ); $result = queryMySql ( "INSERT INTO pictures SET member_id='$user', file_location='$saveto', thumb_location='$thumbLocation'" ); var_dump ( $result ); } else { imagedestroy ( $tmp ); imagedestroy ( $src ); } } catch ( Exception $e ) { throw new Exception ( 'Unable to save to database: ' . $e->getCode () . " || " . $e->getMessage () ); } return $saveto; }
  9. Again, it runs okay on the first run and saves the image to the proper directory but fails when creating the thumbnail....
  10. That is funny, don't even remember coding this..... $directory_self = str_replace ( basename ( $_SERVER ['PHP_SELF'] ), '', $_SERVER ['PHP_SELF'] ); still works fine with the first run again but fails on the second run to create a thumb.... $upload_directory = $_SERVER ['DOCUMENT_ROOT'] . $_SERVER ['PHP_SELF'] . "$userDirectory/"; $saveto = "$upload_directory" . time () . ".jpg"; var_dump /home/(myusername)/(myDomain).com/2/images/1381624178.jpg" took out my username and domain for security.....
  11. Hey guys, Need a little help here, this function works fine the first time around, but I have added some logic to also create a thumbnail of the uploaded image. the function is recursive and at the end calls itself, the problem is the second time around where the move_uploaded_file function fails. Any help would be appreciated! function imageUpload($file, $user, $isThumb = FALSE) { // create thumbnail or save picture if ($isThumb) { $userDirectory = $_SESSION['member_id'] . "/images/thumbs"; $max = 100; } else { $userDirectory = $_SESSION['member_id'] . "/images"; $max = 800; } /* For Debugging, this will properlly check to see if image has been selected if ($file['image']['name'] == "") throw new Exception ( 'No image selected' ); */ // current directory $directory_self = str_replace ( basename ( $_SERVER ['PHP_SELF'] ), '', $_SERVER ['PHP_SELF'] ); $upload_directory = $_SERVER ['DOCUMENT_ROOT'] . $directory_self . "$userDirectory/"; $saveto = "$upload_directory" . time () . ".jpg"; var_dump($saveto); echo "<br />"; var_dump($file); echo "<br />"; if (! makeDir ( "$upload_directory" )) throw new Exception ( 'Error creating location on server, please try again...' ); if (! move_uploaded_file ( $file ['image'] ['tmp_name'], $saveto )) throw new Exception ( 'Error copying image to server, please try again...' ); switch ($file ['image'] ['type']) { case 'image/gif' : $src = imagecreatefromgif ( $saveto ); break; case 'image/jpeg' : case 'image/pjpeg' : $src = imagecreatefromjpeg ( $saveto ); break; case 'image/png' : $src = imagecreatefrompng ( $saveto ); break; default : // invalid image type throw new Exception ( 'Error, invalid file type. Please upload only (.gif, .png or .jpg)' ); break; } list ( $w, $h ) = getimagesize ( $saveto ); $tw = $w; $th = $h; if ($w > $h && $max < $h) { $th = $max / $w * $h; $tw = $max; } elseif ($h > $w && $max < $h) { $tw = $max / $h * $w; $th = $max; } elseif ($max < $w) { $tw = $th = $max; } try { $tmp = imagecreatetruecolor ( $tw, $th ); imagecopyresampled ( $tmp, $src, 0, 0, 0, 0, $tw, $th, $w, $h ); imageconvolution ( $tmp, array ( array ( - 1, - 1, - 1 ), array ( - 1, 16, - 1 ), array ( - 1, - 1, - 1 ) ), 8, 0 ); try { imagejpeg ( $tmp, $saveto ); } catch (Exception $e) { throw new Exception('Error with function imagejpeg() ' . $e->getMessage()); } } catch ( Exception $e ) { throw new Exception ( 'Error Code: ' . $e->getCode () ); } try { if (!$isThumb) { echo "About to create thumbnail for image<br />"; //create thumbnail for image $thumbLocation = imageUpload($file, $user, TRUE); var_dump($thumbLocation); $result = queryMySql ( "INSERT INTO pictures SET member_id='$user', file_location='$saveto', thumb_location='$thumbLocation'" ); var_dump($result); } else{ imagedestroy ( $tmp ); imagedestroy ( $src ); } } catch ( Exception $e ) { throw new Exception ( 'Unable to save to database: ' . $e->getCode () . " || " . $e->getMessage()); } return $saveto; } Here is the output from my var_dump's and catch statements.... $file is $_FILES..... any help would be greatly appreciated!
×
×
  • 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.