[PHP] Re: Resizing an image

2011-03-30 Thread Ross McKay
On Tue, 29 Mar 2011 03:21:48 +0300, Andre Polykanine wrote:

>[...]
>My questions are:
>1.  what  are the restrictions of ImageCopyResampled()? Can I make a jpg
>image  from  a jpg one, and a png image from a png one? And what about
>gif's?

Yes, or even a JPEG from a GIF, or a PNG from a JPEG, etc. 

But: imagecopyresampled works on image *resources*, which you create
either as "blank canvases" or by reading from files. In your case, you
want to create a resource from a file (JPEG, PNG, GIF etc.) and another
as a blank canvas into which you will copy the original image, resampled
(or resized). See the examples here:

http://au2.php.net/manual/en/function.imagecopyresampled.php

After the comment "// Resample" it:
* creates a new blank image resource to copy into, i.e. $dst_image
* creates an image by reading a file, i.e. $src_image
* copies with resampling, i.e. from $src_image to $dst_image

>2.  I  don't  need to output the image as the script output, I need to
>upload it as a file (replacing the uploaded larger file). Could I make
>it with fwrite and then copy it to the server? All of the examples give 
>header("image/jpeg")...

You can write the new image to a file using one of these:

http://au2.php.net/manual/en/function.imagepng.php
http://au2.php.net/manual/en/function.imagejpeg.php
http://au2.php.net/manual/en/function.imagegif.php


NB: see the following comments by tim (at) leethost (dot) com, regarding
performance of imagecopyresampled vs imagecopyresized:

http://au2.php.net/manual/en/function.imagecopyresampled.php#77679
http://au2.php.net/manual/en/function.imagecopyresampled.php#72606

Also check out ImageMagick, if your host provides it (or you can install
it):

http://au2.php.net/manual/en/book.imagick.php
-- 
Ross McKay, Toronto, NSW Australia
"Let the laddie play wi the knife - he'll learn"
- The Wee Book of Calvin

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Path question

2011-03-30 Thread Richard Quadling
On 29 March 2011 19:41, D. Dante Lorenso  wrote:
> On 3/28/11 8:18 PM, Jack wrote:
>>
>> Hello All,
>> Is there a smarter way to do includes by setting up a path or something
>> where I don't have to include /home/domain.com/includes/include_file.php
>> Apparently my path is as shown above,  but I would prefer to just put in
>> /includes/include_file.php
>
> I wrote about this a long time ago ... perhaps it might help:
>
> http://www.dantescode.com/2007/10/10/evolution-of-php-coder-naming-classes/
>
> Talks about putting your functions into classes and using the autoloader to
> avoid putting include statements in your code.
>
> Might not help if you are loading content which is not just PHP
> functions/code, but if you haven't "evolved" this far yet, the read might
> help you out.
>
> -- Dante
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

The Zend Framework documentation has some notes regarding of
autoloading of resources.

http://framework.zend.com/manual/en/learning.autoloading.resources.html

You may find some mileage there.



-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Grasping class / controllers

2011-03-30 Thread Aleksandar Skodric

Hi all,

I am using Codeigniter framework, tho' I believe my question is more PHP 
related in general.


Problem I am having is following.

Codeigniter (CI) uses general class CI_Controller for all functions.
I have extended this controller with: abstract class CORE_Controller 
extends CI_Controller {...}.


Then, I also have a RESTFul library which is:
class Cpin2_rest {}

And, last one is Ion Auth library which states:
class Ion_auth {}

In the Ion auth, there (should be) is initialization of CI_Controller with:

$this->ci =& get_instance();

However, $this->ci inherits Cpin2_rest instead of CI_Controller (or 
CORE_Controller).


I really have no idea where have I made a mistake and can't get around 
this one :(


Any help is appreciated!

Thanks!
Aleks

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Grasping class / controllers

2011-03-30 Thread Ashley Sheridan
"Aleksandar Skodric"  wrote:

>Hi all,
>
>I am using Codeigniter framework, tho' I believe my question is more
>PHP
>related in general.
>
>Problem I am having is following.
>
>Codeigniter (CI) uses general class CI_Controller for all functions.
>I have extended this controller with: abstract class CORE_Controller
>extends CI_Controller {...}.
>
>Then, I also have a RESTFul library which is:
>class Cpin2_rest {}
>
>And, last one is Ion Auth library which states:
>class Ion_auth {}
>
>In the Ion auth, there (should be) is initialization of CI_Controller
>with:
>
>$this->ci =& get_instance();
>
>However, $this->ci inherits Cpin2_rest instead of CI_Controller (or
>CORE_Controller).
>
>I really have no idea where have I made a mistake and can't get around
>this one :(
>
>Any help is appreciated!
>
>Thanks!
>Aleks
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php


That's completely CodeIgniter, not php. The mvc framework layout is something 
used by many languages, but questions about the framework aren't questions you 
should ask of the language but the framework.


Thanks
Ash
--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Grasping class / controllers

2011-03-30 Thread Aleksandar Skodric

Hi,

Yes indeed you are correct.
Found out that framework was loading libraries from array in specific 
order, whereby one overrules the next one.


Anyway, problem solved by rearranging the order of the array :)

Thanks anyway :)

On 03/30/2011 04:13 PM, Ashley Sheridan wrote:

"Aleksandar Skodric"  wrote:


Hi all,

I am using Codeigniter framework, tho' I believe my question is more
PHP
related in general.

Problem I am having is following.

Codeigniter (CI) uses general class CI_Controller for all functions.
I have extended this controller with: abstract class CORE_Controller
extends CI_Controller {...}.

Then, I also have a RESTFul library which is:
class Cpin2_rest {}

And, last one is Ion Auth library which states:
class Ion_auth {}

In the Ion auth, there (should be) is initialization of CI_Controller
with:

$this->ci =&  get_instance();

However, $this->ci inherits Cpin2_rest instead of CI_Controller (or
CORE_Controller).

I really have no idea where have I made a mistake and can't get around
this one :(

Any help is appreciated!

Thanks!
Aleks

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


That's completely CodeIgniter, not php. The mvc framework layout is something 
used by many languages, but questions about the framework aren't questions you 
should ask of the language but the framework.


Thanks
Ash


--
With kind regards,

Aleksandar Skodric
aleksan...@skodric.com
+31652612685


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Slow sessions.

2011-03-30 Thread Rob Adams

On 3/28/2011 3:40 PM, Bostjan Skufca wrote:

Great, please report back if/when you discover the cause.


After searching for some information about the error messages I was 
getting on the file server, I found this:


http://www.spinics.net/lists/linux-nfs/msg14679.html

I ran 'server nfslock status', and it wasn't even running (rpcbind 
wasn't recognized as a service).  So I started the nfslock service and 
it immediately fixed the problem.  I checked the config, and the service 
wasn't set to start in level 3, so I turned that on.  It's been running 
for over 24 hours now with no problems.


Thanks again Bostjan for the help.  I don't think I could have narrowed 
down the problem without using the strace.


  -- Rob


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Permission Denied - Help Requested - Solved

2011-03-30 Thread Ethan Rosenberg

At 12:07 AM 3/30/2011, Adam Richardson wrote:

On Tue, Mar 29, 2011 at 8:21 PM, Ethan Rosenberg wrote:

> At 05:33 PM 3/29/2011, Adam Richardson wrote:
>
>> >
>> > Thanks.
>> >
>> > What do you see if you run this?   "Can't open or create file!"
>> >
>> > Ethan
>>
>>
>> OK,
>>
>> If you're running PHP as an Apache module, by default it won't have
>> permissions to write to the directory (this is by design to avoid security
>> issues.) You can do something like the following:
>>
>>
>>   1. Create a directory for writing files outside of your public directory
>>
>>   (let's call it "uploads".)
>>   2. Change the group associated with the directory to Apache:
>>
>>   sudo chgrp -R www-data /home/username/path/to/uploads
>>   3. Change the permissions on the directory so the group has write
>>
>>   permissions:
>>   sudo chmod -R 2775 /home/username/path/to/uploads
>>   4. Then try the script again.
>>
>>
>> See if that works.
>>
>> Adam
>>
>> --
>> Nephtali:  A simple, flexible, fast, and security-focused PHP framework
>> http://nephtaliproject.com
>>
> 
>
> Thanks -
>
> The directory is output_files, which is a subdirectory of /var/www
> I'm getting a message "invalid owner" on the command "chown Apache
> output_files".  Also with the -R option, and with apache as the owner, also
> with the chgrp.  All these commands are run as root..
>
>
> Help and advice please.
>
> Ethan
>
>
Hi Ethan,

I might be missing something.

Did you set up the user Apache? On a standard install for Debian (using
apt-get), apache is usually set up as the user/group www-data:
http://wiki.debian.org/Apache

The root user typically owns the /var/www
directory. I usually set up virtual hosts within one of the other accounts
and then change the group on a directory outside of the public directory
specifically set aside for uploads and run the commands I sent.

However, in the case of your example, I believe you can just run the 2
commands I sent on the /var/www/output_files directory and you should be
able to write the files.

sudo chgrp -R www-data /var/www/output_files
sudo chmod -R 2775 /var/www/output_files

Hope this helps, and sorry if I misunderstood something in your
configuration or troubleshooting.

Adam

--
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com



Adam -

Thanks.

Works beautifully.

Ethan 




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Session Variables - Error

2011-03-30 Thread Ethan Rosenberg

Dear List -

Thanks for your help.

Here is another one.

I cannot get my session variables to work. The program will print out 
a chess board and show the positions of the pieces after the move


Here are code snippets: The program is chess2.php


$results = array(array("Br", "Bn", "Bb", "Bq", "Bk", "Bb", "Bn", 
"Br"),array("Bp", "Bp", "Bp", "Bp", "Bp", "Bp", "Bp", "Bp"),
array("", "", "", "", "", "", "", 
""),array("", "", "", "", "", "", "", ""),array("", "", "", "", "", 
"", "", ""),
array("", "", "", "", "", "", "", 
""),array("Wp", "Wp", "Wp", "Wp", "Wp", "Wp", "Wp", "Wp"),
array("Wr", "Wn", "Wb", "Wq", "Wk", "Wb", 
"Wn", "Wr"));


$_SESSION['results'] = $results;
print_r($_SESSION);
}
else
{
 $results = $_SESSION['results'];
 echo "starting values";
 print_r($results);
}
?>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>

http://www.w3.org/1999/xhtml";>

.
.
.
.
.

Move Fromname="move_from">
Move To  name="move_to">





";
echo "from_before = "; print_r($from_before);
echo"";
$to = '$'. $_POST[move_to];
echo "to = $to";
//$to = $from;
$from = '' ;
echo"";
echo "from after = $from";
echo"";
echo "to after = $to";

$board = array  //Correlation of input array [chessboard] with 
internal array [results]

(
a8 => $results[0][0],
b8 => $results[0][1],
c8 => $results[0][2],
d8 => $results[0][3],
e8 => $results[0][4],
f8 => $results[0][5],
.
.
.
.
f1 => $results[7][5],
g1 => $results[7][6],
h1 => $results[7][7],
);
for($i = 0; $i <8; $i++) //  I get the correct results here
{
for ($j = 0; $j < 8; 
$j++)

printf("%s ", $results[$i][$j]);
printf("");
}
$_SESSION['results'] = $results;



Ethan 




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Slow sessions.

2011-03-30 Thread Bostjan Skufca
Nice of you to post the resolution of your problem. Glad to hear it is fixed
now.

Take care,
b.


On 30 March 2011 17:46, Rob Adams  wrote:

> On 3/28/2011 3:40 PM, Bostjan Skufca wrote:
>
>> Great, please report back if/when you discover the cause.
>>
>
> After searching for some information about the error messages I was getting
> on the file server, I found this:
>
> http://www.spinics.net/lists/linux-nfs/msg14679.html
>
> I ran 'server nfslock status', and it wasn't even running (rpcbind wasn't
> recognized as a service).  So I started the nfslock service and it
> immediately fixed the problem.  I checked the config, and the service wasn't
> set to start in level 3, so I turned that on.  It's been running for over 24
> hours now with no problems.
>
> Thanks again Bostjan for the help.  I don't think I could have narrowed
> down the problem without using the strace.
>
>  -- Rob
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


[PHP] Sessions - More Info

2011-03-30 Thread Ethan Rosenberg

Dear List -

Thank you for your help in the past.  This an update on my session problems.

Here is a simple test program.  It never increments the session 
counter; ie, does not detect that $_SESSION has been set.




"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>

http://www.w3.org/1999/xhtml";>







I have no idea what is wrong.

I need to make my session variables work so that I can finish a project.

Help and advice, please.

Ethan Rosenberg

MySQL 5.1  PHP 5.3.3-6  Linux [Debian (sid)] 




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Sessions - More Info

2011-03-30 Thread Ashley Sheridan
On Wed, 2011-03-30 at 19:20 -0400, Ethan Rosenberg wrote:

> Dear List -
> 
> Thank you for your help in the past.  This an update on my session problems.
> 
> Here is a simple test program.  It never increments the session 
> counter; ie, does not detect that $_SESSION has been set.
> 
> 
> 
>  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> http://www.w3.org/1999/xhtml";>
> 
> 
> 
>  
> 
> if(isset($_SESSION['views']))
> $_SESSION['views']=$_SESSION['views']+1;
> else
> $_SESSION['views']=1;
> echo "Views=". $_SESSION['views'];
> ?>
>  
> 
> 
> I have no idea what is wrong.
> 
> I need to make my session variables work so that I can finish a project.
> 
> Help and advice, please.
> 
> Ethan Rosenberg
> 
> MySQL 5.1  PHP 5.3.3-6  Linux [Debian (sid)] 
> 
> 
> 


That code works perfectly for me, only thing I would change is the

$_SESSION['views']=$_SESSION['views']+1;

line to

$_SESSION['views']++;

for readability. If you're using Firefox, grab the Firebug plugin, which
should show you the headers that are being sent to and from the server
to the browser. From that, you might get an idea why the sessions don't
seem to be working. Just to make sure, turn on display_errors in your
php.ini file and restart Apache. Some whitespace (space or new line, for
example) before that first http://www.ashleysheridan.co.uk




[PHP] is there a static constructor?

2011-03-30 Thread D. Dante Lorenso

All,

I want to build a config file class that gets called statically.  Is 
there such a thing as a static constructor?  Example:


class Daz_Config {
  public static function load() {
...
  }
  public static function get($key) {
self :: load();
...
  }
}

Daz_Config :: get('myvalue');

I want to call the load function when the class is used for the first 
time.  If no code ever calls "Daz_Config :: get(...)" then I never want 
to invoke load() but if it does get called, I only want to call load() 
once before the class is used further.


Anyone know how to do this with calling load() at the top of all the 
other functions and writing a load() function that exits early if 
already loaded?


-- Dante

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] is there a static constructor?

2011-03-30 Thread Ryan
There is such thing, but its not called static constructor, its called 
singleton pattern

class SingletonA
{
  public static instance;
  public SingletonA(){}
  public static function getInstancce()
  {
if(self::instance != null)
{
  return self::instanc;
}
return new SingletonA();
  }
}

On 3/31/2011 12:56 AM, D. Dante Lorenso wrote:

All,

I want to build a config file class that gets called statically.  Is 
there such a thing as a static constructor?  Example:


class Daz_Config {
  public static function load() {
...
  }
  public static function get($key) {
self :: load();
...
  }
}

Daz_Config :: get('myvalue');

I want to call the load function when the class is used for the first 
time.  If no code ever calls "Daz_Config :: get(...)" then I never 
want to invoke load() but if it does get called, I only want to call 
load() once before the class is used further.


Anyone know how to do this with calling load() at the top of all the 
other functions and writing a load() function that exits early if 
already loaded?


-- Dante




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Sessions - More Info - SOLVED

2011-03-30 Thread Ethan Rosenberg

At 07:28 PM 3/30/2011, Ashley Sheridan wrote:

On Wed, 2011-03-30 at 19:20 -0400, Ethan Rosenberg wrote:

> Dear List -
>
> Thank you for your help in the past.  This an update on my 
session problems.

>
> Here is a simple test program.  It never increments the session
> counter; ie, does not detect that $_SESSION has been set.
>
> 
>
>  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> http://www.w3.org/1999/xhtml";>
> 
> 
>
> 
>
> if(isset($_SESSION['views']))
> $_SESSION['views']=$_SESSION['views']+1;
> else
> $_SESSION['views']=1;
> echo "Views=". $_SESSION['views'];
> ?>
>  
> 
>
> I have no idea what is wrong.
>
> I need to make my session variables work so that I can finish a project.
>
> Help and advice, please.
>
> Ethan Rosenberg
>
> MySQL 5.1  PHP 5.3.3-6  Linux [Debian (sid)]
>
>
>


That code works perfectly for me, only thing I would change is the

$_SESSION['views']=$_SESSION['views']+1;

line to

$_SESSION['views']++;

for readability. If you're using Firefox, grab the Firebug plugin, which
should show you the headers that are being sent to and from the server
to the browser. From that, you might get an idea why the sessions don't
seem to be working. Just to make sure, turn on display_errors in your
php.ini file and restart Apache. Some whitespace (space or new line, for
example) before that first http://www.ashleysheridan.co.uk


++
Ash -

Thanks.

What did it was to 1] explicitly declare the character set and 2] 
close and restart Apache.


Ethan 




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] is there a static constructor?

2011-03-30 Thread Peter Lind
On 31 March 2011 06:56, D. Dante Lorenso  wrote:
> All,
>
> I want to build a config file class that gets called statically.  Is there
> such a thing as a static constructor?  Example:
>
> class Daz_Config {
>  public static function load() {
>    ...
>  }
>  public static function get($key) {
>    self :: load();
>    ...
>  }
> }
>
> Daz_Config :: get('myvalue');
>
> I want to call the load function when the class is used for the first time.
>  If no code ever calls "Daz_Config :: get(...)" then I never want to invoke
> load() but if it does get called, I only want to call load() once before the
> class is used further.
>
> Anyone know how to do this with calling load() at the top of all the other
> functions and writing a load() function that exits early if already loaded?
>

The concept doesn't really make sense - a class that never gets
instantiated never gets constructed, hence no static constructor (nor
a static destructor). You'll have to call your "constructor" function
at the top of the static methods you'll be using - just check inside
the constructor if it's been called before or not.

Regards
Peter


-- 

WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] session_start() may take 5 seconds :(

2011-03-30 Thread Tolas Anon
My web-app sometimes takes just over 5 seconds to execute a single
start_session() statement.
No other connections are open to the site when i hit the button that
makes this happen, the session is just 78kb on a local disk, and it's
consistent behavior.
So far, it only happens when i request certain page content via AJAX,
but I'd like to get rid of it asap.
Strangely, some other page content requested under the same conditions
via the same pipeline returns without the delay. It doesn't do
anything differently except the business code, and the session is
opened in app-wide generic code that is executed before the business
code is executed. The very timing with microtime() happens before the
business code executes.

I've already googled, but haven't found anything useful.

It's on a windows box (latest wampserver) and due to a ubuntu firefox
limitation i can't test on linux at the moment, nor run strace on it
:(

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_start() may take 5 seconds :(

2011-03-30 Thread Negin Nickparsa
session1.php:

session2.php:



Re: [PHP] session_start() may take 5 seconds :(

2011-03-30 Thread Tolas Anon
On Thu, Mar 31, 2011 at 8:10 AM, Negin Nickparsa  wrote:
> session1.php:
>  session_start();
> $_SESSION['s1']='sth';
> header("location: session2.php?".SID);
> ?>
> session2.php:
>  session_start();
> if(isset($_SESSION['s1']))
> echo $_SESSION['s1'];
> else
> die("No session!");
> ?>
>
>

ok, that executes with success and fast..

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php