Hi,
this is the script i made
// Create image
$img = imagecreatetruecolor($w, $h);
// Transparent image
$white = imagecolorallocate($img,255,255,255);
imagefilledrectangle($img,0,0,$w,$h,$white);
imagecolortransparent($img, $white);
//imagealphablending( $img, true );
//imagesavealpha( $img, true );
// Shape color
$bgColor = imagecolorallocatealpha($img, 100, 250, 250, 70);
imagefilledrectangle($img, 15, 20, 50, 100, $bgColor);
imagefilledrectangle($img, 10, 25, 60, 100, $bgColor);
imagepng($img, 'file.png');
the problem is the rectangles are transparent among them but not with the background
i mean, i need to create a transparent image with a semi transparent shape inside
any suggestions?
thanks for your help
Hi,
I am using the code below to upload an image through ftp
$sFile=$ftp_dir."/".$image_name;
$image=$database_row["image"];//image is store in database
$fh = tmpfile();
$fwrite($fh, $image);
$uploadFile = ftp_fput($conn_id, $sFile, $fh, FTP_ASCII);
fclose($fh);
The ftp is creating the file and has a size BUT the file i get is not an image.When try to open on image viewer i get error.
Before switch to ftp i had this code
$image=$database_row["image"];//image is store in database
$file = fopen( "images/".$image_name, "w" );
fwrite( $file, $image);
fclose( $file );
and was working fine, but now i have to use ftp.
What am i missing.
$_SERVER['REMOTE_USER'] returns the username of the user logged in to an Active Directory. I want to retrive this users info by using ldap_search().
This is what I have now:
$ad = // ldap_connection id
$filter = "(|(sn=$username*)(givenname=$username*))";
$attr = array("displayname", "mail", "mobile", "homephone", "telephonenumber", "streetaddress", "postalcode", "physicaldeliveryofficename", "l");
$dn = // OU, DC etc..
ldap_search($ad,$dn,$filter,$attr);
It works, but i'm not sure it will work if two users have almost the same names.
How do I only search for their unique username so that i always only get one user?
Hi all,
I've got a, I think fairly easy question, but this is bugging me for a while now. So I figured, maybe I can get some help here.
Since recursive functions are always a bit tricky, and sometimes a bit unclear to me, I keep struggling to create a nice working solution to get my menudata.
In one of my classes I have this function, which gives me all menu-items recursivly. The thing I want is to determine at which recursionlevel a certain object was retrieved so I can create a nicely looking HTML output with indents for the levels of nesting.
public function GetObjectList($parentID = 0, $objectlist = null)
{
if(is_null($objectlist))
{
$objectlist = new ObjectList("Model_Navigation");
}
$query = MySQL::Query("SELECT * FROM `Navigation` WHERE `WebsiteID` = ".SITE_ID. " AND `LanguageID` = ".LANG_ID." AND `ParentID` = ".$parentID);
while($result = MySQL::FetchAssoc($query))
{
$object = new Model_Navigation();
$object->ID = $result["ID"];
$object->WebsiteID = $result["WebsiteID"];
$object->LanguageID = $result["LanguageID"];
$object->ParentID = $result["ParentID"];
$object->Name = $result["Name"];
$object->Page = Model_Page::GetObjectByID($result["PageID"]);
$object->ExternalURL = $result["ExternalURL"];
$object->Index = $result["Index"];
$object->Level = [here lies my problem];
$objectlist->Add($object);
self::GetObjectList($object->ID, $objectlist);
}
return $objectlist;
}
Hope to hear from you!
Greetings from Holland,
Ben Fransen
Hello, can't understand mysql error:
UPDATE static_pages SET order = " Some
new data 222222
"Database error: You have an error in
your SQL syntax; check the manual that
corresponds to your MySQL server
version for the right syntax to use
near 'order = "
$query = 'UPDATE someTable SET '.$key.' = "'.$value.'"';
Here is $key = order; $value = 'new data 222222';
There is such keys in table: order, prices, contacts. Each of these updates well except the 'order'. Why?
Hi,
I was wondering how I could sort this array, when I use asort right now it does
14
17
16
15.
How would I go to have
14
15
16
17
array(4) {
[15]=> array(9) {
[2025]=> string(80) "20:25 à 21:15 Spectacle / L'histoire d'un coeur / Auditorium, É.S.P. De La Salle"
[2135]=> string(71) "21:35 à 22:25 Spectacle / Transfugue 2 / Auditorium, É.S.P. De La Salle"
[1430]=> string(64) "14:30 à 15:30 Mise en lecture/Théâtre la Catapulte / De La Salle"
[110]=> string(44) "11:00 à 13:00 Inscription / Pavillon Tabaret"
[1330]=> string(49) "13:30 à 14:30 CÉRÉMONIE D'OUVERTURE / De La Salle"
[1550]=> string(61) "15:50 à 16:40 Spectacle/Université Laurentienne / De La Salle"
[170]=> string(57) "17:00 à 17:50 Spectacle/Université d'Ottawa / De La Salle"
[1750]=> string(45) "17:50 à 19:00 REPAS DE L'AMITIÉ / De La Salle"
[1915]=> string(76) "19:15 à 20:05 Spectacle / Attendre la pluie / Auditorium, É.S.P. De La Salle" }
[16]=> array(8) {
[1845]=> string(81) "18:45 à 19:35 Spectacle / Mimes d'horreur / Salle Académique, Université d'Ottawa"
[1955]=> string(73) "19:55 à 20:45 Spectacle / Déroute / Salle Académique, Université d'Ottawa"
[8]=> string(45) "08:30 à 11:30 Atelier / ABC du jeu dramatique"
[13]=> string(41) "13:00 à 16:00 Atelier / Théâtre physique"
[1130]=> string(28) "11:30 à 13:00 DÎNER LIBRE / "
[1620]=> string(29) "16:20 à 18:20 SOUPER LIBRE / "
[220]=> string(58) "22:00 à 23:30 BAL MASQUÉ / l'Agora du centre universitaire"
[210]=> string(47) "21:00 à 22:00 Rétroaction / Université d'Ottawa" }
[17]=> array(4) {
[950]=> string(79) "09:50 à 10:40 Spectacle / Raison d'être / Salle Académique, Université d'Ottawa"
[110]=> string(76) "11:00 à 11:50 Spectacle / Potionnée / Salle Académique, Université d'Ottawa"
[120]=> string(28) "12:00 à 13:00 DÎNER LIBRE / "
[1330]=> string(48) "13:30 à 14:30 CÉRÉMONIE DE CLÔTURE / De La Salle" }
[14]=> array(1) {
[150]=> string(49) "15:00 à 16:30 Préparation technique / De La Salle" } }
I have a project where I need a penny auction. Rather than doing it from scratch I would like to hear if you know any "ready-to-go" scripts for that?
There are alot of them out there but most seems dodgy.
I have no problem tweaking/customizing such scripts. I just don't want to start from scratch.
I need a way to convert a number into formatted way by inserting comma at suitable places. Can it be done using regex?
Example:
12345 => 12,345
1234567 =>1,234,567
I have a select menu that displays countries. It looks at the DB and judging by the value in the db shows the option as selected. Is there a simpler way off doing this than:
if ($country == 'AG') {echo '<option value="AG" selected="selected">Antigua</option>';}
else {echo '<option value="AG">Antigua</option>';};
if ($country == 'AR') {echo '<option value="AR" selected="selected">Argentina</option>';}
else {echo '<option value="AR">Argentina</option>';};
if ($country == 'AM') {echo '<option value="AM" selected="selected">Armenia</option>';}
else {echo '<option value="AM">Armenia</option>';};
if ($country == 'AW') {echo '<option value="AW" selected="selected">Aruba</option>';}
else {echo '<option value="AW">Aruba</option>';};
if ($country == 'AU') {echo '<option value="AU" selected="selected">Australia</option>';}
else {echo '<option value="AU">Australia</option >';};
if ($country == 'AT') {echo '<option value="AT" selected="selected">Austria</option>';}
else {echo '<option value="AT">Austria</option>';};
if ($country == 'AZ') {echo '<option value="AZ" selected="selected">Azerbaijan</option>';}
else {echo '<option value="AZ">Azerbaijan</option>';};
if ($country == 'BS') {echo '<option value="BS" selected="selected">Bahamas</option>';}
else {echo '<option value="BS">Bahamas</option>';};
if ($country == 'BH') {echo '<option value="BH" selected="selected">Bahrain</option>';}
else {echo '<option value="BH">Bahrain</option>';};
There are a lot of countries and doing this would be madness wouldn't it????
My application requires the user to enter their business name, which the application will automatically create into a unique identifier to be used in URLs, ie
"Bob's Cafe" will become "bobs-cafe"
But if there are duplicate names I would like the application to add a number so if there is already a "bobs-cafe" we will use "bobs-cafe-1" and likewise if there is already a "bobs-cafe-1" we will use "bobs-cafe-2"
Ive used explode and also looked at a regular expressions but I dont know the best way to approach this.
Im stuck in being able to grab the number and incrementing it and returning the string
What I need to do is have a data structure that shows jobs organised into 14 day periods, but only when an id is the same. I've implemented all sorts of stuff, but they have failed miserably.
Ideally, maybe a SQL expert could handle all of this in the query.
Here is some of my code. You can assume all library stuff works as expected.
$query = 'SELECT date, rig_id, comments FROM dor ORDER BY date DESC';
$dors = Db::query(Database::SELECT, $query)->execute()->as_array();
This will return all jobs, but I need to have them organised by 14 day period with the same rig_id value.
$hitches = array();
foreach($dors as $dor) {
$rigId = $dor['rig_id'];
$date = strtotime($dor['date']);
if (empty($hitches)) {
$hitches[] = array(
'rigId' => $rigId,
'startDate' => $date,
'dors' => array($dor)
);
} else {
$found = false;
foreach($hitches as $key => $hitch) {
$hitchStartDate = $hitch['startDate'];
$dateDifference = abs($hitchStartDate - $date);
$isSameHitchTimeFrame = $dateDifference < (Date::DAY * 14);
if ($rigId == $hitch['rigId'] AND $isSameHitchTimeFrame) {
$found = true;
$hitches[$key]['dors'][] = $dor;
}
}
if ($found === false) {
$hitches[] = array(
'rigId' => $rigId,
'startDate' => $date,
'dors' => array($dor)
);
}
}
}
This seems to work OK splitting up by rig_id, but not by date. I also think I'm doing it wrong because I need to check the earliest date.
Is it possible at all to do any of this in the database query?
To recap, here is my problem
I have a list of jobs with all have a rig_id (many jobs can have the same) and a date.
I need the data to be organised into hitches. That is, the rig_id must be the same per hitch, and they must span a 14 day period, in which the next 14 days with the same rig_id will be a new hitch.
Can someone please point me on the right track?
Cheers
Hi guys,
I've got this code
mysqli_query ( $userdatabase,
'CREATE TABLE `user_'.$emailreg.'` (
ID int NOT NULL AUTO_INCREMENT PRIMARY KEY,
IP varchar(10),
FLD1 varchar(20),
FLD2 varchar(40),
FLD3 varchar(25),
FLD4 varchar(25),
FLD5 varchar(25) )' );
echo ( mysqli_error ($userdatabase) );
that works fine on my localhost, but when I upload it to the server, it starts giving me a "Incorrect table name '[email protected]'" error. any idea?
Thanks!
Is it necessary to validate a name or street address? when I have it coded in the following format. And if so why?
$address = mysqli_real_escape_string($mysqli, htmlentities($_POST['address']));
$name = mysqli_real_escape_string($mysqli, htmlentities($_POST['name']));
The snippet below loops through some web pages, grabs the html and then looks for table.results and gets the plaintext out of the tags contained in each . $results is ok.
Now I'm trying to get the href value of an tag that is found in the second of each . I'd like to include this in the $results array, but I'm not sure how to do this. The third foreach statement gets them but then I need to merge $links with $results. Ideally I'd also get the links in the second foreach statement.
Does anyone know how?
$i = 0;
foreach( $urls as $u )
{
$html = file_get_html($u);
foreach($html->find('.results tbody tr') as $element)
{
$result[$i] = $this->extract($element->plaintext);
$i++;
}
foreach($html->find('.results tbody tr a') as $element)
{
$links[$i] = $element->href;
$i++;
}
}
print_r($result);
print_r($links);
die;
Here I have a variable 'response' which is obtained by parsing an XML file.
$url = 'http://xxxxx.xml';
$ch = curl_init($url);
$response = curl_exec($ch);
The url structure is as follows -
<user>
<id>734</id>
<name>Peter Parker</name>
-
<status>
<favorited>false</favorited>
</status>
</user>
How to access each bit of info like id,name,favorited from response?
array(
[0]
name => 'joe'
size => 'large'
[1]
name => 'bill'
size => 'small'
)
I think i'm being thick, but to get the attributes of an array element if I know the value of one of the keys, I'm first looping through the elements to find the right one.
foreach($array as $item){
if ($item['name'] == 'joe'){
#operations on $item
}
}
I'm aware that this is probably very poor, but I am fairly new and am looking for a way to access this element directly by value. Or do I need the key?
Thanks,
Brandon
I'm not using an off-the-shelf framework and don't particularly want to (nor d I want to go into the reasons why...). Anyway, onto my question(s), I hope it make sense....
I'm trying to get my head around what should go in the model and what should go in the controller. Originally I had the impression that a model class should represent an actual object (eg - a car from the cars table of a database) and model properties should mirror the database fields. However I'm now getting the feeling that I've got the wrong idea - should an instance of a model class represent an actual item, or should it contain a number of methods for doing stuff - sometimes to one car or sometimes to multiple cars based on my example earlier.
For example I want to get all the cars from a the database and show them in the view. Am I right in think it should be along the lines of this?
Controller File
function list() {
$cars = $this->model->get_all();
$this->view->add($cars);
$this->view->render('cars-list');
}
Model File
function get_all() {
// Use a database interaction class that I've written
$cars = Database::select();
return $cars;
}
Now, if the car had a "status" field that was stored as an integer in the database and I wanted to change that to a string, where should that be done? By looping the SQL results array in the get_all() method in the model?
Also, where should form validation live? I have written a validation class that works a little like this:
$validator = new Validator();
$validator->check('field_name', 'required');
If the check fails, it adds an error message to the array in the Validator. This array of error messages would then get passed to the view. Should the use of my validator class go in model or the controller?
Thanks in advance for for any help anyone can offer. If you know of any links to a simple MVC example / open source application that deals with basic CRUD, they would be much appreciated.
I hate that google can not search for symbols. I saw this in some sample code and wondered why there is an @ sign before the readfile function:
@readfile($filename);
What does it mean different to without an @ symbol?
I am using REPLACE INTO query to insert in to table but after executing query by using mysql_query() function and if I use last_insert_id() it is only giving me 0 value.
why this is happening so? and how can I overcome this behavior.
:Pankaj
Hello,
I am using this IP Validation Function that i came across while browsing, it has been working well until today i ran into a problem.
For some reason the function won't validate this IP as valid: 203.81.192.26
I'm not too great with regular expressions, so would appreciate any help on what could be wrong.
If you have another function, i would appreciate if you could post that for me.
|--------------------------------------------|
The code for the function is below:
|--------------------------------------------|
public static function validateIpAddress($ip_addr)
{
global $errors;
$preg = '#^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}' .
'(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$#';
if(preg_match($preg, $ip_addr))
{
//now all the intger values are separated
$parts = explode(".", $ip_addr);
//now we need to check each part can range from 0-255
foreach($parts as $ip_parts)
{
if(intval($ip_parts) > 255 || intval($ip_parts) < 0)
{
$errors[] = "ip address is not valid.";
return false;
}
return true;
}
return true;
} else {
$errors[] = "please double check the ip address.";
return false;
}
}
This article states that
If your site is run on a shared Web
server, be aware that any session
variables can easily be viewed by any
other users on the same server.
On a larger host like GoDaddy, are there really no protections in place against this? Could it really be that easy? If it is that easy, where are the session vars of the other users on my host so I can check them out?
Edit: I didn't believe it, but here's my little program which shows that this is true! I wonder if those are really the same as the value stored in the cookies on the users' machine?