Archive for the 'PHP' Category
<form enctype="multipart/form-data" action="up.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000"/>
Chooseafiletoupload:<input name="uploadedfile" type="file"/><br/>
<input type="submit" value="UploadFile" name="Submit"/>
</form>
<?php
if (isset($_POST[’Submit’])){
$target_path="upload/";
$target_path=$target_path.basename($_FILES[’uploadedfile’][’name’]);
if(move_uploaded_file($_FILES[’uploadedfile’][’tmp_name’],$target_path)){
$myFile = "upload/".$_FILES[’uploadedfile’][’name’];
}
else{echo "could not upload";}
[/cc]
Number of Columns and Rows in CSV using php
0 Comments Published March 10th, 2010 in PHP, Programming Tags: No Tags.How to get the # of columns and rows from a csv using php
[Can be useful when parsing a csv, e.g: creating a table in a database from a csv - need to know # of columns]
2 ways
//using FGETCSV
$myFile = "THEFILE.csv";
$row = 0;
if (($handle = fopen($myFile , "r")) !== FALSE) {
while (($data = [...]
How to get url with Jquery and PHP
0 Comments Published February 24th, 2010 in JavaScript, PHP, Programming Tags: No Tags.current URL in address bar
PHP
$pageURL= $pageURL= $_SERVER["REQUEST_URI"].$_SERVER["REQUEST_URI"];
Jquery
$(document).ready(function() {
var pathname = window.location.pathname;
alert (pathname);
});
Todays date selected in date fields
1 Comment Published September 2nd, 2009 in PHP, Programming Tags: No Tags.POOR mans way of doing this, 3 combo box’s with day/month/year, with todays date already selected,
using my previous changing variable name method
<?php
$day = date("d");
$month = date("m");
$year = date("y");
${’daysel’.$day} = ’selected="selected"’;
${’monthsel’.$month} = ’selected="selected"’;
${’yearsel’.$year} = ’selected="selected"’;
?>
<html>
<form>
<table>
<tr>
<td><select name="day">
<option value="01" <?php echo $daysel01; ?>>1</option>
<option value="02" <?php echo $daysel02; ?>>2</option>
<option value="03" <?php echo $daysel03; [...]
Check for checkbox’s [PHP]
0 Comments Published August 27th, 2009 in PHP, Programming Tags: No Tags.To check which checkbox is selected, or if both are selected, in PHP
<input type="checkbox" name="coupons[]" value="1" >
<input type="checkbox" name="coupons[]" value="2" >
checker in php
if (isset($_POST[’Submit’])) {
$state=$_POST[’coupons’];
foreach ($state as $statename)
{
$x = $statename;
$ugh .= $x;
}
if 1 is selected, result will be 1
if 2 is selected result will be 2
if both are selected, result will be 12
go forward using [...]
Removing duplicates from several CSV/Excel files.
1 Comment Published August 5th, 2009 in PHP, Programming Tags: No Tags.One can use ‘remove duplicates’ in excel but what if there are over 200k records, split into several csv files/spread sheets.
Easiest solution is to upload to database and add a checking method before hand.
1-Check if email already exists in table
2-If email does not exist then add email to table
<?php
ini_set(’max_execution_time’, 0);
//connect to database/table
$array = file("1.csv");
foreach ($array [...]
PHPlist list only displaying 1-50
0 Comments Published July 28th, 2009 in PHP, Programming Tags: No Tags.Bug where phplist only displays 1-50 in a list, when more users exist [the back < and next > buttons do not function ]
<strong>Change members.php on line 205</strong>
if (isset($start) && $start) {
$start = sprintf(’%d’,$_REQUEST["start"]);
<strong>To:</strong>
if (isset($_GET[’start’]) && (int) $_GET[’start’] > 0) {
$start = (int) $_GET["start"];
source: http://mantis.phplist.com/view.php?id=15282
Jquery/PHP Irish mobile number validation [regular expressions]
0 Comments Published July 28th, 2009 in JavaScript, PHP, Programming Tags: No Tags.PHP
<?php
$pattern = "/^(083|086|085|086|087)\d{7}$/";
$phone = "087343266";
if (preg_match($pattern,$phone)) echo "Match";
else echo "Not match";
Jquery
$.validator.addMethod("phoneNumber", function(value, element) {
return /^(083|086|085|086|087)\d{7}$/.test(value);}, " Not Valid");
$(document).ready(function(){
$("#reg").validate({
rules: {
mobile:{required:true,
number:true,
minlength:10,
phoneNumber:true
}},
Push csv entries into an array
0 Comments Published May 27th, 2009 in PHP, Programming Tags: No Tags.A csv with 2 columns, id and email, will be stored respectively in $x
<?php
set_time_limit(300000);
$array2 = file("all.csv");
foreach($array2 as $line)
{
$x[] = list($id[],$email[]) = $line;
}
echo $x[1];
?>
PHP - increment variable name within a loop
4 Comments Published May 26th, 2009 in PHP, Programming Tags: No Tags.<?php
for ( $i = 0; $i <= 10; $i++)
{
${’var’.$i } = $i ;
echo ${’var’.$i};
}
?>
Categories |
||||
Latest Photos on Flickr |
||||






