scootstah
Staff Alumni-
Posts
3,858 -
Joined
-
Last visited
-
Days Won
29
Everything posted by scootstah
-
How to load value to text field when choose value in select
scootstah replied to mrbhb's topic in PHP Coding Help
You need to do that with Javascript. Here is the doc page for jQuery's .change() : http://api.jquery.com/change/ -
Yes, you can do it that way, but it's much less efficient and overall not very good design. The article that I linked explains the differences.
-
You basically have to set a bunch of mail headers. Did you Google this? There's tons of tutorials and information about it. Regardless, I recommend you use a library such as PHPMailer or SwiftMailer. They can both easily send email attachments.
-
You can't reliably get the file extension from the file name. You could use $_FILES['cv']['name'], but it will be whatever the user sets it to. Instead, you can save the file with the extension it should have based on its MIME. However, Apache should be configured to serve content based on the MIME and not the file extension.
-
You'd also face that problem with any link on your site. If you "change your files around", the links will break. There is a solution to that, though: use a routing library. That way you can have a static route key that will map a URI to a page/class/function/something. That way, you use the route key in your links (and in this case, the form field) and then you're golden. As long as the route key stays the same, you can change the link as much as you want.
-
The exact solution depends on how you want the nesting to behave. If you only want comments to be nested 1 level deep, then you can just add a "parent_id" column to your comments table. If you want more than 1 level, you'll probably want to go with a hierarchical tree design. Check out this article for more information on that.
-
So? That's their problem. They could also type a URL into the address bar. This is really just a UX design feature. If the user purposefully breaks that... well, oh well.
-
You could possibly write to a temporary file, and then use the MySQL command-line utility to insert the file. You won't have memory issues this way, and can insert a very large amount of data.
-
That will prevent directory listing, but not prevent people from running scripts directly or accessing files that they shouldn't have access to. In such a case, you can use deny from all in an .htaccess file to completely prevent access through Apache to those directories. You can skip the .htaccess and put this directly into the virtual host if you like, which gives you a lot more power and control. For example, you can target specific directories/files with paths that way. EDIT: This really shouldn't be done with PHP; Apache can do it much better.
-
Actually, there is good reasons behind that. On shared hosting, it can be more secure. It's also sometimes faster, and easier to cluster. You also have better control over session life/persistence.
-
You could set a session variable on the registration page. $_SESSION['from_registration'] = true;
-
Registration and Upload not working
scootstah replied to IlaminiAyebatonyeDagogo's topic in PHP Coding Help
Alright, touché. -
I've done some for various different forums in the past. An easy way to handle it is to just work out what the forms need for data (like the login form, or registration form) and then simply send that data to the URL that normally processes it in the forum. If you're lucky, the forum will already be able to handle AJAX requests or something, which makes this even easier. It depends how deeply you need to integrate it.
-
You need to put enctype="multipart/form-data" in your form tag.
-
The easiest way would be to tap into the forum's user/session management code. The specifics depend on which software you pick, but there's a good chance that someone has already done it and written a tutorial or something.
-
Best way to check if one array values less than another array?
scootstah replied to RuleBritannia's topic in PHP Coding Help
I'm not 100% clear on what you're looking for. Your original wording was that you "want to check if array 0 values are all less than array 1." So, this should do that: $array1 = array( 'width' => 400, 'height' => 300, 'start' => 200, 'end' => 10 ); $array2 = array( 'width' => 4000, 'height' => 30, 'start' => 20, 'end' => 100 ); function aLessThanB($a, $b) { foreach($a as $key => $val) { if ($val > $b[$key]) { return false; } } return true; }This will return true if all elements of array1 are < the corresponding elements of array2, otherwise it will return false. Part of me also thinks that perhaps you want to retrieve the lower value for each element between array1 and array2. So, this will do that: $array1 = array( 'width' => 400, 'height' => 300, 'start' => 200, 'end' => 10 ); $array2 = array( 'width' => 4000, 'height' => 30, 'start' => 20, 'end' => 100 ); function getLowestValues($a, $b) { $c = array(); foreach($a as $key => $val) { $c[$key] = min($val, $b[$key]); } return $c; } Returns: Array ( [width] => 400 [height] => 30 [start] => 20 [end] => 10 ) -
Makes the form fail how? Are you getting an error? You'd still be allowing the user to type in a username, but then forcibly replacing it - that's a little confusing for the user. It's also not fool-proof, as the user can still set the data before it reaches your server. If you want to force their username, you should do it when processing the AJAX request. You can set the input field attribute for "disabled", which will not let the user edit the field. This way they know what the value the name will be. You should still force the username when processing the AJAX request, though, as it's still possible for it to be modified by the user.
-
Registration and Upload not working
scootstah replied to IlaminiAyebatonyeDagogo's topic in PHP Coding Help
That is not true, it will work either way. Though, you should write it like you say, because that is true to the spec. -
Using strings for "no" or "yes" really make no sense at all. This is exactly what booleans are for (true/false). $fieldExists = (empty($trimValue) ? false : $trimValue);
-
broken image still showing over correct image
scootstah replied to ryanmetzler3's topic in PHP Coding Help
If I'm understanding it correctly, you just need to have a valid URL to a default image. $url = 'http://'.dirname($_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]).'/img/default_avatar.gif';This link returns a 404. So if you just change this line to a valid image URL, you should be okay. -
Give it the full absolute path, not a relative path.
-
broken image still showing over correct image
scootstah replied to ryanmetzler3's topic in PHP Coding Help
But what happens when you look at the HTML source for that <img /> element? Do you see two <img />'s? As for the 404, I'm not really seeing how it would be requesting that image from the code you've provided. Are you requesting that image somewhere else? -
I could see MySQL getting steadily replaced by MariaDB in the future, due to Oracle's general shittiness. As far as MySQL vs PostgreSQL.... ehhhh. A lot of it is personal preference, or whichever you're more comfortable with. Both can be tuned to scale high. Both have tons of features, and you can pretty much accomplish the same things in both. It also depends on what you're building. If you're building something in-house where you can control the environment, then either are great options. However, if you're building something that will be distributed out in the wild, then perhaps MySQL would be better, since it is more likely to be supported on random web hosts (this problem can be mitigated by using PDO, though).
-
Try this: $result = unserialize($api->getResponseSerialized()); foreach ($result->products as $product) { edit $product->field1; }
-
broken image still showing over correct image
scootstah replied to ryanmetzler3's topic in PHP Coding Help
What do you see when you inspect the element?