|
Sab669 posted:Interesting, thanks for the resource. I'm actually in class right now and these computers don't have a way to handle .gz files So I'll look at it when I get home, I suppose. What are the permissions on the images folder? It seems like this is where it is having the issue.
|
# ? Sep 14, 2011 14:05 |
|
|
# ? Jun 6, 2024 17:43 |
|
Both tmp and images have full read/write/execute privileges.
|
# ? Sep 14, 2011 15:34 |
|
I'm a Java guy, so please bear with me. How do I get php to return the full aliased column name in a result set? I've got a large query with multiple joins, and each table in the join has a column named "id". Each "id" is aliased in the query as a.id, b.id, c.id, but $result->fetch_assoc only returns "id" instead of "a.id", "b.id", "c.id". It's stripping the table name off the columns, and since fetch_assoc returns a hashmap, I only get the last value.
|
# ? Sep 14, 2011 19:09 |
|
blargle posted:I'm a Java guy, so please bear with me. How do I get php to return the full aliased column name in a result set? I've got a large query with multiple joins, and each table in the join has a column named "id". Each "id" is aliased in the query as a.id, b.id, c.id, but $result->fetch_assoc only returns "id" instead of "a.id", "b.id", "c.id". It's stripping the table name off the columns, and since fetch_assoc returns a hashmap, I only get the last value. Is it possible to revise the query to alias all of these? Or, if the order is set, you can use mysql_fetch_array() or mysql_fetch_row() instead and use the numeric indices.
|
# ? Sep 14, 2011 19:41 |
|
I'm not sure what you mean by "alias all of these", isn't that what I'm already doing (a.id, b.id, c.id)?
|
# ? Sep 14, 2011 19:44 |
|
blargle posted:I'm not sure what you mean by "alias all of these", isn't that what I'm already doing (a.id, b.id, c.id)? No, more like ... 'SELECT a.id AS a_id, b.id AS b_id, c.id AS c_id'.
|
# ? Sep 14, 2011 19:47 |
|
So I ticketted the support team for my hosting company about the apparent permission issue.quote:What's the location of the script? Also, are you mixing up paths? The /var/www/html that you see via FTP or the File Manager is not the same path PHP sees. You would want to prepend $_SERVER['SITE_ROOT'] per this article[1]. I'm not sure how stupid this mistake was on my part, but either way I'm just happy it's fixed.
|
# ? Sep 14, 2011 22:32 |
|
What's a safe way to detect if a file is an MP3?
|
# ? Sep 20, 2011 01:12 |
|
If you're on a Unix, you can shell out to the "file" command and parse the result. Calling "file -b foo.mp3" should result in something like "Audio file with ID3 version 23.0 tag, MP3 encoding". "file -bi foo.mp3" should result in the MIME type "audio/mpeg"
|
# ? Sep 20, 2011 01:33 |
|
http://de3.php.net/manual/en/function.finfo-file.php
|
# ? Sep 20, 2011 02:12 |
|
McGlockenshire posted:If you're on a Unix, you can shell out to the "file" command and parse the result. Calling "file -b foo.mp3" should result in something like "Audio file with ID3 version 23.0 tag, MP3 encoding". "file -bi foo.mp3" should result in the MIME type "audio/mpeg" Thanks, that sounds reasonable. This doesn't seem safe: php:<? $file_sanitized = escapeshellarg($file); echo exec("file -bi $file_sanitized"); ?> Biowarfare posted:http://de3.php.net/manual/en/function.finfo-file.php Thanks for this too, next time I recompile PHP I'll consider adding this module. Acer Pilot fucked around with this message at 23:20 on Sep 20, 2011 |
# ? Sep 20, 2011 23:11 |
|
quote:This doesn't seem safe:
|
# ? Sep 21, 2011 01:57 |
|
Will doing something like this ever cause any issues:php:<?php function foo() { echo 'hello world'; } function bar($param) { echo 'you passed: '.$param; } $fooFunc = foo; $barFunc = bar; $fooFunc(42); $barFunc(1234); ?> I'm asking because I have a function reference which sometimes will take a variable and sometimes won't. So should I just pass variables and not worry, or should I do a check to make sure parameters are only passed to functions which are defined to take one?
|
# ? Sep 21, 2011 19:38 |
|
Optimus Prime Ribs posted:I'm asking because I have a function reference which sometimes will take a variable and sometimes won't. Well, PHP supports default argument values, so you can have both: php:<? function foo($bar=null) { if ($bar !== null) { return $bar; } }?> php:<? function bar() { if (func_num_args() > 0) { $args = func_get_args(); } }?> Yay fucked around with this message at 20:20 on Sep 21, 2011 |
# ? Sep 21, 2011 20:18 |
|
Yay posted:This latter method demonstrates why your original code won't throw errors (though it may throw warnings/notices; I really can't remember) php:<? function foo() {} function bar($baz) {} foo('bar'); // No errors bar(); // Throws a "missing argument" warning (in 5.3, at least) ?>
|
# ? Sep 21, 2011 20:36 |
|
Optimus Prime Ribs posted:Will doing something like this ever cause any issues: You'll see two warnings, one for the assignment of $fooFunc and another for the assignment of $barFunc. You should also see a warning to the call to bar with no params, as DaTroof pointed out.
|
# ? Sep 21, 2011 20:38 |
|
Yay posted:Well, PHP supports default argument values, so you can have both: Oh, I know I could do that. Just seemed redundant since some functions won't ever use the passed parameter. McGlockenshire posted:You don't have your error reporting level turned up high enough. Try error_reporting(-1); ini_set('display_errors', true);. I had a feeling that might have been the issue. I'll go ahead and implement a check so that it doesn't happen anymore. Thanks. e: Missed something in your post. Is it not possible to create a reference to a function in PHP? Optimus Prime Ribs fucked around with this message at 20:52 on Sep 21, 2011 |
# ? Sep 21, 2011 20:47 |
|
Optimus Prime Ribs posted:Is it not possible to create a reference to a function in PHP? Yes, but the variable needs to be a string representation of the function name: php:<? $fooFunc = 'foo'; $barFunc = 'bar'; ?>
|
# ? Sep 21, 2011 21:16 |
|
DaTroof posted:Yes, but the variable needs to be a string representation of the function name: All right, that makes sense. Would that mean that the code 'foo'() will call the function "foo"? (not that I would ever need to do that; just making sure I understand)
|
# ? Sep 21, 2011 21:24 |
|
Optimus Prime Ribs posted:All right, that makes sense. Hahaha, I wouldn't have been surprised if that worked, but apparently it doesn't. The string has to be in a variable, not a literal or a constant.
|
# ? Sep 21, 2011 21:30 |
|
DaTroof posted:Hahaha, I wouldn't have been surprised if that worked, but apparently it doesn't. The string has to be in a variable, not a literal or a constant. PHP never stops being fun. Thanks though.
|
# ? Sep 21, 2011 21:39 |
|
n/m, someone said that already
|
# ? Sep 21, 2011 22:20 |
|
McGlockenshire posted:It depends. If you control the filename, then it's totally safe. If the user controls the filename, as long as you've either filtered out non-alphanumerics or are also using escapeshellcmd, then you should be OK. Thanks, this is what I'm using right now. I control the filename but you never know. php:<? $file_sanitized = escapeshellarg($file); $file_type = exec(escapeshellcmd("file -bi $file_sanitized")); ?>
|
# ? Sep 22, 2011 01:13 |
|
drcru posted:Thanks, this is what I'm using right now. I control the filename but you never know. I dunno if it needs to be safer, but if you want it to be more secure you can only allow certain characters in the file name and maybe a single period with a 3 digit extension. Then you can write a regular expression to test for this and fail if it doesn't conform to your rules.
|
# ? Sep 22, 2011 17:57 |
|
What's the general consensus on DataMapper ORM for CodeIgniter? For one of the projects I'm working on I've ended up building my own ORM library for CI that's more lightweight and (I hope) more intuitive. Would it be worth releasing it to the general community or are people pretty happy with DataMapper?
|
# ? Sep 27, 2011 09:27 |
|
I need curl help. Trying to navigate this website: http://iowahospitalcharges.com/Web/InpatientServices.aspx It gets the cities automatically, and I am trying to get the Facilities dropdown to work. I'm using the following code (starting with Carroll as an example) php:<? // Initialize the CURL variables $rCurl = curl_init(); $aPost = array('category' => 'Company', 'knownCategoryValues' => 'City:Carroll;'); $sCookieFile = '/tmp/php_files/foo'; @unlink($sCookieFile); // Get the info curl_setopt($rCurl, CURLOPT_POST, TRUE); curl_setopt($rCurl, CURLOPT_POSTFIELDS, $aPost); curl_setopt($rCurl, CURLOPT_URL, 'http://iowahospitalcharges.com/WebService.asmx/GetFacilitiesForCity'); curl_setopt($rCurl, CURLOPT_REFERER, 'http://iowahospitalcharges.com/Web/InpatientServices.aspx'); curl_setopt($rCurl, CURLOPT_COOKIEFILE, $sCookieFile); curl_setopt($rCurl, CURLOPT_COOKIEJAR, $sCookieFile); curl_setopt($rCurl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1; rv:7.0) Gecko/20100101 Firefox/7.0'); $sCurl = curl_exec($rCurl); curl_close($rCurl); echo $sCurl; ?> This is on PHP 5.1.6. (Though we may finally be getting 5.3 soon! )
|
# ? Sep 28, 2011 23:21 |
|
Golbez posted:curl stuff Correct me if I'm wrong, but that's a web service. You should be able to make calls to the service using the PHP SoapClient class with http://iowahospitalcharges.com/WebService.asmx?WSDL as your wsdl. Should be much more reliable than curl (and easier).
|
# ? Sep 29, 2011 01:57 |
|
Null Set posted:Correct me if I'm wrong, but that's a web service. You should be able to make calls to the service using the PHP SoapClient class with http://iowahospitalcharges.com/WebService.asmx?WSDL as your wsdl. Should be much more reliable than curl (and easier). Looks promising, thanks, I'll try it tomorrow. But, still, shouldn't I be able to replicate the browser's POST call in curl?
|
# ? Sep 29, 2011 04:10 |
|
Some sites built using older ASP.NET techniques use Javascript page state postbacks and a horrible abomination of client and server-side session keeping. This can make it very difficult to automate access to them.
|
# ? Sep 29, 2011 05:29 |
|
McGlockenshire posted:Some sites built using older ASP.NET techniques use Javascript page state postbacks and a horrible abomination of client and server-side session keeping. This can make it very difficult to automate access to them. I turned off cookies and it still seemed to work... hm. And yeah, just looking at the Javascript, it's *way* too complex for what's going on here. You don't need to load five different scripts for a simple dropdown tree. Golbez fucked around with this message at 14:30 on Sep 29, 2011 |
# ? Sep 29, 2011 14:11 |
|
Golbez posted:I turned off cookies and it still seemed to work... hm. And yeah, just looking at the Javascript, it's *way* too complex for what's going on here. You don't need to load five different scripts for a simple dropdown tree. I have to do this poo poo all the time because some of our vendors can't be bothered to get a SOAP interface set up. There are a couple of extensions that firefox has to make your life easier. First get NoScript and visit the page to see if it works without javascript. You'll also want to install liveHTTPHeaders. Turn on capture in liveHTTPHeaders and then either post to the page normally (no javascript) or make it fire whatever AJAX call it does on the page that brings up the data you want. In this case, the facilities appear to be returned by an AJAX call to http://iowahospitalcharges.com/WebService.asmx/GetFacilitiesForCity with what looks like JSON data being passed? {"knownCategoryValues":"City:Carroll;","category":"Company"} After you're sending it the right data, you just have to parse what you get back.
|
# ? Sep 29, 2011 14:38 |
|
Doctor rear end in a top hat posted:I have to do this poo poo all the time because some of our vendors can't be bothered to get a SOAP interface set up. There are a couple of extensions that firefox has to make your life easier. First get NoScript and visit the page to see if it works without javascript. You'll also want to install liveHTTPHeaders. Turn on capture in liveHTTPHeaders and then either post to the page normally (no javascript) or make it fire whatever AJAX call it does on the page that brings up the data you want. You managed to quote me before I took that out; php-soap was there, but only showing up in sudo yum. And I was using Firebug to find out that data, and trying to use curl to send it back, I thought. But all I get is the error screen. Maybe the problem is that I'm sending each variable in a POST instead of one JSON object. Either way, SOAP appears to be the way to go on this. Edit: Soap's been working, I managed to get the facility list... and then the site went down, only showing the error message. Surely it's not because of me? Golbez fucked around with this message at 15:46 on Sep 29, 2011 |
# ? Sep 29, 2011 14:41 |
|
It came back up... and then it dropped again while I was testing things. Could it be that PHP is clogging their connection pool? Is there any way to get around that? I'm even throttling the connections with sleep(5) after each one.
|
# ? Sep 29, 2011 17:58 |
|
Golbez posted:It came back up... and then it dropped again while I was testing things. Could it be that PHP is clogging their connection pool? Is there any way to get around that? I'm even throttling the connections with sleep(5) after each one. Can you post your code? How many requests are you sending at once?
|
# ? Sep 29, 2011 18:35 |
|
Null Set posted:Can you post your code? How many requests are you sending at once? One. I think. I have one $oSoap = new SoapClient($wsdl) and I simply reuse that variable.
|
# ? Sep 29, 2011 19:06 |
|
Golbez posted:One. I think. I have one $oSoap = new SoapClient($wsdl) and I simply reuse that variable. That line retrieves the WSDL (the web service definition xml file). How are you actually sending your requests for data to the remote service? Should be something like $oSoap->butts(array($key1=>$value1));
|
# ? Sep 29, 2011 19:11 |
|
Null Set posted:That line retrieves the WSDL (the web service definition xml file). How are you actually sending your requests for data to the remote service? Right. $oCities = $oSoap->GetCities($oSearch), then foreaching that to get each facility; getting all categories, foreaching that to get all subcategories; etc. If I'm the one killing their server by running a few hundred requests, each throttled by 3 seconds, then, really, that's not my fault.
|
# ? Sep 29, 2011 19:23 |
|
Golbez posted:Right. $oCities = $oSoap->GetCities($oSearch), then foreaching that to get each facility; getting all categories, foreaching that to get all subcategories; etc. Yeah, that sounds like they have some sort of throttling on their end. Is this a script you only need to run once to grab all this data? Or is it something that's going to have to be run repeatedly? If it only needs to be run once, you could just track how far you get, then resume from there. Or you could contact them and see if they can add a service that you can call once to get the exact information you need, instead of making repeated calls.
|
# ? Sep 29, 2011 19:34 |
|
Null Set posted:Yeah, that sounds like they have some sort of throttling on their end. Throttling would make sense. The whole thing shutting down and displaying an error message to everyone - not just me - is very nonsensical. Thankfully, this is indeed a list that can be pulled a little at a time and stored.
|
# ? Sep 29, 2011 19:46 |
|
|
# ? Jun 6, 2024 17:43 |
|
I was trying to teach myself cakephp but a post in this thread caused me to start investigating Symfony2, and it seems a lot better. Is netbeans a good IDE for php/symfony2? I'm fine with just using vi but idk what's out there
|
# ? Oct 1, 2011 21:30 |