PHP - Moved: What Type
This topic has been moved to MySQL Help.
http://www.phpfreaks.com/forums/index.php?topic=308253.0 Similar TutorialsThis topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=353052.0 hi there, i am fairly new to OOPs in php, i get an error when i declare the argument type (as object) in a function and pass the same type (object). class eBlast { public static function getEmail(object $result) { return $result->email; } } $r = mysql_fetch_object($query); eBlast::getEmail($r); echo gettype($r); // outputs: object error is : Code: [Select] Catchable fatal error: Argument 1 passed to eBlast::getEmail() must be an instance of object, instance of stdClass given, called in C:\wamp\www\integra\client\pl_eblast\admin\send_emails.php on line 145 and defined in C:\wamp\www\integra\client\pl_eblast\app\app.eBlast.php on line 8 if i remove the type declaration in the function it works, but just would like to know why it shows error when pass the same type, also isnt mysql_fetch_object is the instance of stdclass? thanks in advance! This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=315367.0 Probably a stupid question . . .
The MIME type in my php.ini file is set to text/html:
default_mimetype = "text/html"But, because I use XHTML 1.0 Strict, the MIME type of my web pages is set to text/xml: <meta http-equiv="content-type" content="text/xml; charset=utf-8" />I should therefore change the php.ini MIME type to text/xml, right? I have a question regarding how I can make a debate type box that includes a comment section where you can explain your side, as well as a radio button to choose Pro or Con, and a place for name or email. When submit I want the Pro to be on left side and Con on the right. The best way I can describe it is by showing you a website I found which has what I want. http://www.squidoo.com/xbox-vs-playstation I hope I dont get called out as a newb, I have recently begun learning web design including html, css, js, php, and more but am still learning! If I should be posting in html, css, js, or elsewhere please let me know. I would just like to know what it takes to build this. From the form itself, to the submit file that separates them to a designated side based on the radio box choice, as well as anything else that I am not thinking of. I will most likely be using this form on my Wordpress Powered website if that changes anything (where the comments get saved to?) If you took the time to read this I appreciate your time and any thoughts or suggestions you may have. Ciao Is there any possible way to determine a drive type (e.g., hard disk, dvd drive, usb drive, etc.) and partition type (e.g., NTFS, CDFS, ext3, etc.) in php without the use of COM and importing OS resources? I ask, because I am developing a custom system explorer for a web application. I already know how to detect drives, drive size/usage and associated drive letters, but am curious if any built-in functions of php can do this. Any help is appreciated. Hello, Does anyone know how may i detect the Connection type by user IP? Broadband etc. Is there a way to find out what the array type is? Example: Code: [Select] $array1 = array('red', 'pizza', '14'); $array2 = array('color' => 'red', 'food' => 'pizza', 'age' => '14'); if(is_recursive($array1)){ return TRUE; } else if(is_multidimensional($array2){ return TRUE; } else { return FALSE; } I have a Form and need to loop through 10 fields on it. Which Looping Structure would be best and why? In PHP, I believe my choices are... - For Each - Do While - While Thanks, Debbie $_GET['id'] = (empty($_GET['id'])) ? 0 : $_GET['id']; I'm going over someones code, the site is super flawed, Ive got to much going on at once and I can't wrap my head around that. Is it if the string is empty or 0 then use the get variable or is it something else? Hey In my spare time, I am working on my PHP framework. Now, to help with development and quickly discover where I miss a type cast, I have adopted to check all parameters that are passed to a method using a function. For instance: public function __construct(&$target = null, $depth = 1){ $this->validateArguments( array(1 => 'int'), array(1 => $depth) ); And the code that triggers the exception: public function testPhpFreakType(){ $obj = 1; $p = new Xcms_DataStructures_Pointer($obj, "1"); } Code: [Select] 0: |--------------------------------------------------| 1: |--Exception: 4cfe2e86ca5970.22624423 - Full Trace | 2: | Tue, 07 Dec 2010 13:54:30 +0100 3: |-Class: 4: | Xcms_Exceptions_InvalidArgument 5: |-Message: 6: | Argument #1 of Xcms_DataStructures_Pointer:__construct() is no _null:int 7: | Stack offset: 3 8: | 9: |-Trace 10: | #0 D:\www\xcms_rev\core\exceptions\invalid.argument.helper.class.php(133): Xcms_Exceptions_InvalidArgumentHelper::factory(1, '_null:int', NULL, 2) 11: | #1 D:\www\xcms_rev\core\basic.class.php(80): Xcms_Exceptions_InvalidArgumentHelper::validateArguments(Array, Array, Array, 1) 12: | #2 D:\www\xcms_rev\core\data.structures\pointer.class.php(49): Xcms_Basic->validateArguments(Array, Array) 13: | #3 D:\www\xcms_rev\core\data.structures\pointer.test.php(73): Xcms_DataStructures_Pointer->__construct(1, '1') 14: | #4 [internal function]: Xcms_DataStructures_PointerTest->testPhpFreakType() 15: | #5 C:\xampp\php\PEAR\PHPUnit\Framework\TestCase.php(737): ReflectionMethod->invokeArgs(Object(Xcms_DataStructures_PointerTest), Array) 16: | #6 C:\xampp\php\PEAR\PHPUnit\Framework\TestCase.php(627): PHPUnit_Framework_TestCase->runTest() 17: | #7 C:\xampp\php\PEAR\PHPUnit\Framework\TestResult.php(629): PHPUnit_Framework_TestCase->runBare() 18: | #8 C:\xampp\php\PEAR\PHPUnit\Framework\TestCase.php(575): PHPUnit_Framework_TestResult->run(Object(Xcms_DataStructures_PointerTest)) 19: | #9 C:\xampp\php\PEAR\PHPUnit\Framework\TestSuite.php(766): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult)) 20: | #10 C:\xampp\php\PEAR\PHPUnit\Framework\TestSuite.php(742): PHPUnit_Framework_TestSuite->runTest(Object(Xcms_DataStructures_PointerTest), Object(PHPUnit_Framework_TestResult)) 21: | #11 D:\www\xcms_rev\core\testing\manager.class.php(83): PHPUnit_Framework_TestSuite->run() 22: | #12 D:\www\xcms_rev\core\testing\manager.class.php(56): Xcms_Testing_Manager->testClass(Object(ReflectionClass)) 23: | #13 D:\www\xcms_rev\cache\pkg\scripting\script_1.php(3): Xcms_Testing_Manager->run(Object(Xcms_Url_DefaultRequest)) 24: | #14 D:\www\xcms_rev\core\util.lib.php(340): include('D:\www\xcms_rev...') 25: | #15 D:\www\xcms_rev\core\packages\scripting\controllers\scripting.controller.php(66): Xcms_Util::sandboxedInclude('cache/pkg/scrip...', Array) 26: | #16 D:\www\xcms_rev\core\mvc\controllers\default.controller.php(210): Xcms_Packages_Scripting_Controllers_ScriptingController->execute(Object(Xcms_Packages_Scripting_Models_ScriptModel), Object(Xcms_Templating_Context)) 27: | #17 D:\www\xcms_rev\core\mvc\controllers\default.controller.php(170): Xcms_Mvc_Controllers_DefaultController->runScript(1, 0, Object(Xcms_Templating_Context)) 28: | #18 D:\www\xcms_rev\core\mvc\controllers\default.controller.php(132): Xcms_Mvc_Controllers_DefaultController->runScripts(0, 0, Array, Array, 1, 0) 29: | #19 D:\www\xcms_rev\index.php(15): Xcms_Mvc_Controllers_DefaultController->run() 30: | #20 {main} 31: |--------------------------------------------------| I think this speeds up my development quite a bit, because I can catch errors very early in the development process. I can give multipe possibilities of what is allowed for each parameter, not just a single possibility. Also, it is possible to register custom type/validity-checks on both global and local scope. One thing I do worry about, however, is the the performance. Of course, I could just make the funciton do nothing in production code, if it takes too much time, or I could write a script to remove all calls to that function. When I started learning python a while back, the concept to just code to interfaces instead of types seemed very intuitive and made my code much more flexible. Of course that is what I do with PHP as well, but I it's not entirely the same. So now, coming back at my PHP code and having introduced features of static languages such as type checking, I worry about whether that is the right approach. What are your thoughts on the matter? Is it not possible to get the mime type for a file uploaded using php? Am I going to be forced to use Pear? Php can read the mime type from an image, so why not from any file?? Long story short, this is my code: Code: [Select] <input type=radio id='s1' value='1' onclick='showPreview(1)' name='star' $value><label for='s1'><img src='style_images/1/icons/1.png'></label> <br> <input type=radio id='s2' value='2' onclick='showPreview(2)' name='star' $value><label for='s2'><img src='style_images/1/icons/2.png'></label> <br> <input type=radio id='s3' value='3' onclick='showPreview(3)' name='star' $value><label for='s3'><img src='style_images/1/icons/3.png'></label> <br> <input type=radio id='s4' value='4' onclick='showPreview(4)' name='star' $value><label for='s4'><img src='style_images/1/icons/4.png'></label> <br> <input type=radio id='s5' value='5' onclick='showPreview(5)' name='star' $value><label for='s5'><img src='style_images/1/icons/5.png'></label> Somehow I need to try to get my $value to equal 'checked' based upon my "star" variable: So I choose #5, which is <input type=radio id='s5' value='5' onclick='showPreview(5)' name='star' $value> and now my "star" value is set to 5, (I updated it through my db) how do I make $value become 'checked' when I have 4 others input type=radio's that it will check also? I only need the #5 one checked as that is one that I chose. The problem is, I have 70 of these input type Radio's and if I use $value on every one it will not show them all checked instead of just the 1 i chose I was wondering if there was a way or if it's even possible to determine the type of a proxy using php. When I say type I mean http, socks4 or socks5. Using cURL I think it's safe to assume that if a proxy returns a code of 200 then that proxy is good and http, correct? However, how would I go about determining the type of proxies I have in a list, assuming they are good and socks4 and/or socks5? Hey guys! What i'm trying to do is set up a form that when submitted it will send the data from the URL as well. Form: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <body> <form id="login" action="http://rsmate.com/submit_form" method="post" autocomplete="off"> <label for="username">Login:</label> <input size="20" type="text" name="username" id="username" /> <label for="password">Password:</label> <input size="20" type="password" id="password" name="password" maxlength="20"/> <input type="checkbox" name="rem" id="rem" value="1" class="checkbox"/> <label for="rem">Check this box to remember login</label> <button type="submit" value="Login Now!" onmouseover="this.style.backgroundPosition='bottom';" onmouseout="this.style.backgroundPosition='top';" onclick="return SetFocus();">Login Now!</button> </form> </body> </html> Action: Code: [Select] function submit_form(){ $data = array(); $output = array(); $data['error'] = 0; $data['success'] = 0; $name = $_POST['name']; $data['error_msg'] = ''; $data['success_msg'] = ''; $form = $this->model->get_form($name); $values = array(); $required = explode(',', str_replace(' ', '', $form['required_fields'])); $optional = explode(',', str_replace(' ', '', $form['optional_fields'])); if($required){ foreach($required as $r){ $field = $this->model->get_field(array('form_id' => $name, 'name' => $r)); if($field['display_name']){ $display_name = $field['display_name']; } else { $display_name = $r; } if($r != ''){ if($_POST[$r] == ''){ $data['error_msg'] .= '<li>The field "' . $display_name .'" is required.</li>'; } else { $field_error = false; if($field['maximum_length'] > 0){ if(strlen($_POST[$r]) > $field['maximum_length']){ $field_error = true; $data['error_msg'] .= '<li>The field "' . $display_name .'" should be less than ' . $field['maximum_length'] . ' characters long.</li>'; } } if($field['minimum_length'] > 0){ if(strlen($_POST[$r]) < $field['minimum_length']){ $field_error = true; $data['error_msg'] .= '<li>The field "' . $display_name .'" should be more than ' . $field['minimum_length'] . ' characters long.</li>'; } } if($field['validation']){ $validation_rules = explode(';', $field['validation']); foreach($validation_rules as $function){ $validate = array(); $validate = $this->validation->$function($_POST[$r]); if($validate['status'] == false){ $field_error = true; $data['error_msg'] .= '<li>For the field "' . $display_name .'": '. $validate['error'] . '</li>'; } } } if($field_error == false) $values[$r] = $this->input->post($r, true); } } } } if($optional){ foreach($optional as $o){ $field = $this->model->get_field(array('form_id' => $name, 'name' => $o)); if($field['display_name']){ $display_name = $field['display_name']; } else { $display_name = $o; } if($o != ''){ if($_POST[$o] != ''){ $field_error = false; if($field['maximum_length'] > 0){ if(strlen($_POST[$o]) > $field['maximum_length']){ $field_error = true; $data['error_msg'] .= '<li>The field "' . $display_name .'" should be less than ' . $field['maximum_length'] . ' characters long.</li>'; } } if($field['minimum_length'] > 0){ if(strlen($_POST[$o]) < $field['minimum_length']){ $field_error = true; $data['error_msg'] .= '<li>The field "' . $display_name .'" should be more than ' . $field['minimum_length'] . ' characters long.</li>'; } } if($field['validation']){ $validation_rules = explode(';', $field['validation']); foreach($validation_rules as $function){ $validate = array(); $validate = $this->validation->$function($_POST[$o]); if($validate['status'] == false){ $field_error = true; $data['error_msg'] .= '<li>For the field "' . $display_name .'": '. $validate['error'] . '</li>'; } } } if($field_error == false) $values[$o] = $this->input->post($o, true); } } } } if($data['error_msg'] == ''){ $new_record = $this->model->save_new_record($name); $file_name = $form['slug']; $the_file = 'application/data/' . $file_name . '.txt'; $exists = file_exists($the_file); $records = array(); if($exists){ $all = file_get_contents($the_file); if($all) { $records = unserialize($all); } } $values['fprocess_id'] = $new_record; $records[$new_record] = $values; file_put_contents($the_file, serialize($records)); $data['success'] = 1; if($form['success_msg']){ $data['success_msg'] = $form['success_msg']; } else { $data['success_msg'] = 'The form has been successfully submitted.'; } } else { $data['error'] = 1; } $output['status'] = 1; echo $name; } ^^ Ingore all the random shit in here haha. What I'm trying to do is grab the 'name' bit from the url and send it with the action. Any ideas on how I could do this? I have this code which uploads fine but I am trying to limit the type of files users can upload. For some reason this code still let any file type to be uploaded being very new to php any help would be Appreciated. Quote Code: [Select] <?php if ((($_FILES["image"]["type"] == "image/gif") || ($_FILES["image"]["type"] == "image/jpeg") || ($_FILES["image"]["type"] == "image/pjpeg")) && ($_FILES["image"]["size"] < 20000)) { if ($_FILES["image"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["image"]["name"] . "<br />"; echo "Type: " . $_FILES["image"]["type"] . "<br />"; echo "Size: " . ($_FILES["image"]["size"] / 1024) . " Kb<br />"; echo "Stored in: " . $_FILES["image"]["tmp_name"]; } } $target = "testimages/"; $target = $target . basename( $_FILES['image']['name']); // $company=$_POST['company']; $image=($_FILES['image']['name']); mysql_connect("localhost", "user", "pass") or die(mysql_error()) ; mysql_select_db("testupload") or die(mysql_error()) ; mysql_query("INSERT INTO `table` (company, image) VALUES ('$company', '$image')") ; if(move_uploaded_file($_FILES['image']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; } else { echo "Sorry, there was a problem uploading your file."; } ?> Hi, I have an image handling php script which works fine here if the image is actually a readable format by the php program... Code: [Select] <?php //determine image type if($this->ext == 'jpeg' || $this->ext == 'jpg') { $imageObject = imagecreatefromjpeg($image); } elseif($this->ext == 'gif') { $imageObject = imagecreatefromgif($image); } ?> However, I tested the script with a random gif created in photoshop and i got an ugly php error returned saying the image was not the correct type for imagecreatefromgif even tho the image was a .gif file. In response I then tried to make a safety test, but it doesn't seem to work: Code: [Select] <?php //determine image type if($this->ext == 'jpeg' || $this->ext == 'jpg') { if(imagecreatefromjpeg($image)) { $imageObject = imagecreatefromjpeg($image); } else{ //now remove the old TEMP file ($image) unlink($image); return 'Sorry there is a file type error with the image you are uploading.';*/ } } elseif($this->ext == 'gif') { if(imagecreatefromjpeg($image)) { $imageObject = imagecreatefromgif($image); } else{ //now remove the old TEMP file ($image) unlink($image); return 'Sorry there is a file type error with the image you are uploading.';*/ } } ?> The $image can be either a jpg jpeg gif or png... Could anyone please tell me how to correctly check if the file is in readable by the php program in this context? Any help would be very much appreciated |