Jump to content

scootstah

Staff Alumni
  • Posts

    3,858
  • Joined

  • Last visited

  • Days Won

    29

Everything posted by scootstah

  1. You can use fileinfo to check the file's mimetype. Since you want to check the size, you could alternatively just use getimagesize(), which will return an array of information about the image. If the given file is not an image, the function will fail and thus you will know it's not an image. You can resize with imagecopyresized().
  2. Please use code tags in the future, it makes it easier to read.
  3. Whoa. Are you like, from the future man?
  4. I agree with iarp's solution, except you don't need the TotalLogins on the user table. You can just count the rows from the session tracking table.
  5. I'm not totally clear on what you're trying to do here. But if you simply want to convert newlines to <br/>, there is a function for that.
  6. He means to prefix the table with the database name. Such as, SELECT * FROM databaseName.tableNameinstead of just SELECT * FROM tableName Yes, but when you open the new connection you're not selecting the database that the user created. You can have many databases, you need to tell it which one to use.
  7. It could be a byte order mark. What editor are you using?
  8. Please use code tags and format your code properly. <?php include('config3.php'); if ($_POST) { // $_FILES["file"]["error"] is HTTP File Upload variables $_FILES["file"] "file" is the name of input field you have in form tag. if ($_FILES["file"]["error"] > 0) { // if there is error in file uploading echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { // check if file already exit in "images" folder. if (file_exists("uploads/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { if (move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"])) { // If file has uploaded successfully, store its name in data base $query_image = "INSERT into acc_images (image, status, acc_id) values ('" . $_FILES['file']['name'] . "', 'display','')"; if (mysql_query($query_image)) { } } } } $query_image = "SELECT * FROM acc_images acc_ id='$id'"; $result = mysql_query($query_image); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result)) { echo '<img alt="" src="uploads/' . $row["image"] . '">'; } } echo 'File name not found in database'; } ?> <html> <body> <form action="upload.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file"/> <br/> <input type="submit" name="submit" value="Submit"/> </form> </body> </html>Your code doesn't work because you're not actually storing the file in the file system. Once a file is uploaded in PHP, it is stored in a temporary location until the script is done executing, where it is then deleted. You need to copy the file to a permanent location after it is uploaded. Take a look at move_uploaded_file()
  9. Good point. I think you could use a Reply-To header for that instead of From, to avoid spam filters.
  10. Well, pardon me then. Do you have "allow_url_fopen" turned on in your PHP config? Otherwise things like copy() or fopen() with a remote file will not work. If you can't turn that on, or don't want to, the other option is to use CURL to download the file.
  11. http://stackoverflow.com/a/15140604/1072631 This SO answer has concluded that after trying many things, it's simply not possible to unzip a file in any other way than to have the file in the local file system. You're going to need to download the file and then unzip it.
  12. If it were me I'd go the opposite direction. Leave your quote stuff alone, and fix your underlying foundation. Your quote system is working, and isolated to a couple classes. It's going to be challenging to break that into proper OOP when the rest of your system is procedural spaghetti.
  13. $headers = "From: $email";You're not validating or sanitizing $email, so attackers can inject anything they want into the headers. You need to validate $email so that it can only contain a single, valid email address and nothing more.
  14. That page tells you in pretty good detail how to add pagination. We're not here to write it for you. Where are you having trouble specifically?
  15. True, but then you're repeating that logic every time you need it. A typical routing layer sits in front of the controllers and everything is in one centralized location.
  16. He's basically talking about the Routing layer that I was talking about earlier. The Routing layer will look at the URI and determine where it needs to go. You can either do really loose approach where the first segment is always the controller, the second segment is always the method, and anything after that is arguments. Or, you can do it so that you have to define every route in a file and explicitly state which controller it goes to. I generally prefer the latter. The first way would break up your URI string into segments. So if you had a URI string like: /news/view/17 then we could say that the first segment is supposed to be a controller, the second segment is supposed to be a method within that controller, and any additional segments are arguments to the controller method. So like: class NewsController { public function viewAction($id) { } }You'd have some code that looks to see if that class and method exist, and then invoke it. The other way is with explicitly defined routes. This is how a lot of big frameworks like Symfony2 work. So you'd defined a route with something like this: $routes = array( '/news/view/{id}' => array( 'controller' => 'NewsController', 'method' => 'view', 'options' => array( 'httpMethod' => 'GET', 'params' => array( 'id' => '\d+' ), ) ) );You'd have to do a bit more work in this case, but it scales better. For what it's worth, the Symfony2 Routing component is decoupled and very usable in any project. A whole bunch of open source projects are using this now, including the new PHPBB forum software and Drupal 8. It's very fast and gives you a solid foundation for which to organize your controllers, without having to reinvent the wheel.
  17. Yes it does. I'm running 5.6.7-1 and it works fine. <?php register_shutdown_function('fatal_error_catcher'); function fatal_error_catcher() { $last_error = error_get_last(); if ($last_error['type'] === E_ERROR) { echo '<pre>'; echo print_r($last_error, true); echo '</pre>'; } } throw new Exception('test');Returns: Array ( [type] => 1 [message] => Uncaught exception 'Exception' with message 'test' in /var/www/phpfreaks/error.php:18 Stack trace: #0 {main} thrown [file] => /var/www/phpfreaks/error.php [line] => 18 )
  18. Did you do that by hand? O.o
  19. I made a quick example showing how you'd use AJAX to populate your form, based on a dropdown box. https://jsfiddle.net/8s608y7j/ To make it work with a PHP script, you could simply replace the getUserById() function to send an AJAX request.
  20. Why? The matched blood group is already known. If I am A-, I can just say SELECT ... FROM health_profile WHERE blood_group IN('A-', 'O-'). Your way is more portable, but it can work either way.
  21. You can't use E_ERROR in trigger_error(). You can only use user-space errors, which are: E_USER_NOTICE, E_USER_ERROR, and E_USER_WARNING. The snippet in your first post is indeed how you capture a fatal error, but you're not triggering a fatal error. Just throw an uncaptured exception and I think that will trigger it.
  22. I think we're arguing about different things. Refactoring as you have laid out above is absolutely okay. As you've pointed out, that is the natural process in TDD. It can't be eliminated. What I'm talking about is large scale refactors for something that you thought might work but ended up not. It's easy to make broad assumptions and not realize something stinks until you get to the point that you need it. You might waste a few hours before you hit that point, and then have to refactor a bunch of stuff. If I'm building anything that will consist of more than a couple classes, I like to just sit and jot down what it will look like as a general overview. Write some classes down, some methods that I know I'll need, any dependencies that I think I'll need, how I will get those dependencies in, etc. There is no specifics, and it's generally all very pseudo-codey, but I have something to run with and refer to. EDIT: Anyway, these are just my opinions. Your mileage may vary. I think we're pretty far off topic at this point...
  23. While we're talking about books, I recommend these as well: http://www.amazon.com/Objects-Patterns-Practice-Matt-Zandstra/dp/1430260319 http://www.amazon.com/Refactoring-Experts-Voice-Open-Source/dp/1430227273
  24. TDD means Test Driven Development. Like I said, refactoring is a vital part of development. I'm not arguing there. But that doesn't mean you need to unnecessarily spend hours refactoring when you could have just given a bit of thought to how you build it first. How do you estimate your workload if you have no idea what you're doing before you start? How do you break workload up between team members if nobody knows how it will be built? I find it very beneficial to just grab a notebook and sketch some stuff out before I start. Sometimes I can flush out bad ideas before I waste the time coding them, only to discover they won't work. Or, maybe something is complex and it's just easier to visualize it on paper to prevent insanity. Writing code takes time. There's no point in spending a bunch of time writing code that is inherently flawed.
×
×
  • 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.