PHP
-
(PHP) Allow any delimiter in CSV file
In a Laravel app I made the users would upload CSV files. The problem was that fgetcsv only allows a single delimiter character, and it needs to be defined. The problem with that is that when a user exports a CSV from MS Excel – it could end up using a wide array of delimiters depending on the locality…
-
(PHP) Eloquent doodles for Laravel
[php] // Get model by primary key $myModel = MyModel::find($id); //Where can use short syntax for equal comparison. $myModels = MyModel::where(‘someAttribute’, ‘=’, ‘someValue’)->get(); $myModels = MyModel::where(‘someAttribute’, ‘someValue’)->get(); // Delete models $affectedRows = MyModel::where(‘someAttribute’, ‘someValue’)->delete(); // Select distinct $distincts = MyModel::distinct()->select(‘someAttribute’)->where(‘someAttribute’, ‘someValue’)->get(); // Select with Limit and offset $myModels = MyModel::limit(30)->get(); $myModels = MyModel::limit(30)->offset(30)->get(); [/php] Different…
-
(PHP) simple picture/file upload script
Here is a simple tutorial script that uploads a file to a folder on the server. In this example it is assumed that the file is an image and it will be outputted on screen in an img-tag. But the file uploading mechanics works for any file type. [php] <?php if(isset($_POST[‘submit’])) { $temp_name = $_FILES["file"]["tmp_name"];…
-
How to make OSX use MAMP php instead of system version
Getting OSX to install Laravel properly is a minor nightmare. Here are some good instructions on how to get it to use MAMP php instead of the broken default one that comes with OSX. https://gist.github.com/irazasyed/5987693
-
(PHP) Simple pagination
Here’s a simple way to paginate when getting large amounts of posts from the database.
-
(PHP) Simple gallery with thumbnail generation
This is an enhanced version of this It’s a VERY simple php gallery. You could develop it in any direction. This one only supports jpg, but that could be augmented as well. Here’s what it does: Allows the user to choose an image and enter a title (or caption). Uploads the image to a folder…
-
Simple function to see if a number is Even or Odd.
Sometimes you need to check if a number is even or odd. A simple way to do this is using the modulus operator (the %-sign). It will calculate and return the remainder when dividing a value with another value. So how do you use that to find out if a number is even or odd?…
-
(PHP) Simple e-mail contact form.
A simple contact form, just for reference. Will add more info later on… [php] <?php if (isset($_POST[‘submit’])) { $name = $_POST[‘name’]; //name of sender $email = $_POST[’email’]; //e-mail of sender $email = stripslashes($email); $subject = $_POST[‘subject’]; //e-mail subject $subject = str_replace(array("\r\n","\r","\n"), "", $subject); //remove any linebreaks to keep from code injections $message = $_POST[‘message’]; //…