php-general Digest 30 Mar 2011 08:17:02 -0000 Issue 7250
Topics (messages 312123 through 312137):
Re: Permission Denied - Help Requested
312123 by: Adam Richardson
312126 by: Ethan Rosenberg
312127 by: Al
312128 by: Ethan Rosenberg
312132 by: HallMarc Websites
312134 by: Adam Richardson
312135 by: Ethan Rosenberg
312136 by: Adam Richardson
Re: Resizing an image
312124 by: tedd
312137 by: Ross McKay
Re: Path question
312125 by: D. Dante Lorenso
[DEADLOCK - Code Igniter
312129 by: Tristan
312130 by: Daniel Brown
312131 by: Ashley Sheridan
Re: session variable problem
312133 by: markb
Administrivia:
To subscribe to the digest, e-mail:
[email protected]
To unsubscribe from the digest, e-mail:
[email protected]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
On Mon, Mar 28, 2011 at 11:43 PM, Ethan Rosenberg <[email protected]>wrote:
> At 11:14 PM 3/28/2011, Adam Richardson wrote:
>
>> On Mon, Mar 28, 2011 at 11:03 PM, Ethan Rosenberg <<mailto:
>> [email protected]>[email protected]> wrote:
>> At 01:32 AM 3/28/2011, Hans Ã…hlin wrote:
>> Do you have SELinux installed?
>>
>> 2011/3/28 Ethan Rosenberg <<mailto:[email protected]>
>> [email protected]>:
>>
>> > Dear List -
>> >
>> > Thanks for all your help in the past. Â Here is another one...
>> >
>> > I am getting a Permission Denied" message when I try to run a PHP
>> script. Â I
>> > just changed the mode on the directory and the files to 777. Â This
>> problem
>> > arose when I changed the permissions. Â I thought I was solving a
>> problem,
>> > because I could not open a file for writing. Â I was not receiving error
>> > messages, but no file was created.
>> >
>> > Help and advice, please.
>> >
>> > Ethan Rosenberg
>> >
>> >
>> >
>> **********************************************
>> Â Hans Ã…hlin
>> Â Â Tel: +46761488019
>> Â Â icq: 275232967
>> Â Â <http://www.kronan-net.com/>http://www.kronan-net.com/
>> Â Â irc://<http://irc.freenode.net:6667>irc.freenode.net:6667 - TheCoin
>>
>> **********************************************
>>
>>
>> Hans -
>>
>> Sorry, I did not include my signature, which includes all the requested
>> information.
>>
>> Here it is....
>>
>> Ethan
>> ==========
>> MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)]
>>
>>
>> The problem persists. I cannot write to a file from PHP.
>>
>> Any more suggestions?
>>
>> Thanks.
>>
>> Ethan
>>
>>
>> Hi Ethan,
>>
>> Are you using suPHP or suExec? I believe the server chokes on 777
>> permissions in those cases.
>>
>> Have you checked the permissions in the command line (sorry for the basic
>> question, but just making sure I know what you've already done?)
>>
>> Also, can we see some of the code you're using to handle the file
>> processing?
>>
>> Thanks,
>>
>> Adam
>>
>> --
>> Nephtali: A simple, flexible, fast, and security-focused PHP framework
>> <http://nephtaliproject.com>http://nephtaliproject.com
>>
>
> +++++++++
>
> Adam -
>
> Thanks.
>
> 1] Pardon my ignorance but I do not understand this - Are you using suPHP
>> or suExec?
>>
>
suPHP and suExec are two modules that allow PHP to run with the permissions
of the user, making it easy to write files to disk. However, suPHP (and I
believe suExec, but I can't remember for sure) does not like 777
permissions.
>
> 2] I changed the permissions to 755 and the "Permission Denied" message
> went away.
>
Check!
>
> 3] Have you checked the permissions in the command line? Yes
>
Check!
>
> 4] Here are some code snippets:
>
> $fptr1 = fopen("chessboard", "r+"); //this works
> $fptr2 = fopen('chessboard', 'w'); //this deletes the file, as it should
> for($i = 0; $i <8; $i++)
> {
> for ($j = 0; $j < 8; $j++)
> fprinf($fptr2, "%s ", $results[$i][$j]);
> fprinf($fptr2, "\n");
>
> } //this never writes, so I am left with an empty file
Can you try a simplified form that checks for success along the way? How
about something like the code below to see how far it gets (I haven't
tested, but it should be close):
<?php
// let's make sure you see the E_WARNING errors if present for file
functions
error_reporting(-1);
// set var for later
$cost = 120.89;
if (!($fp = fopen("test.txt", 'w'))) {
echo "Can't open or create file!";
} else if (!($len = fprintf($fp, "In the year 3000, a Coke will cost %01.2f,
with tax.", $cost))) {
echo "Can't write to file!";
} else if (!(fclose($fp))) {
echo "Can't properly close file!";
}
?>
What do you see if you run this?
Adam
--
Nephtali: A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com
--- End Message ---
--- Begin Message ---
At 01:40 PM 3/29/2011, Adam Richardson wrote:
On Mon, Mar 28, 2011 at 11:43 PM, Ethan Rosenberg <[email protected]>wrote:
> At 11:14 PM 3/28/2011, Adam Richardson wrote:
>
>> On Mon, Mar 28, 2011 at 11:03 PM, Ethan Rosenberg <<mailto:
>> [email protected]>[email protected]> wrote:
>> At 01:32 AM 3/28/2011, Hans Ã
hlin wrote:
>> Do you have SELinux installed?
>>
>> 2011/3/28 Ethan Rosenberg <<mailto:[email protected]>
>> [email protected]>:
>>
>> > Dear List -
>> >
>> > Thanks for all your help in the past. Â Here is another one...
>> >
>> > I am getting a Permission Denied" message when I try to run a PHP
>> script. Â I
>> > just changed the mode on the directory and the files to 777. Â This
>> problem
>> > arose when I changed the permissions. Â I thought I was solving a
>> problem,
>> > because I could not open a file for writing. Â I was not receiving error
>> > messages, but no file was created.
>> >
>> > Help and advice, please.
>> >
>> > Ethan Rosenberg
>> >
>> >
>> >
>> **********************************************
>> Â Hans Ã
hlin
>> Â Â Tel: +46761488019
>> Â Â icq: 275232967
>> Â Â <http://www.kronan-net.com/>http://www.kronan-net.com/
>> Â Â irc://<http://irc.freenode.net:6667>irc.freenode.net:6667 - TheCoin
>>
>> **********************************************
>>
>>
>> Hans -
>>
>> Sorry, I did not include my signature, which includes all the requested
>> information.
>>
>> Here it is....
>>
>> Ethan
>> ==========
>> MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)]
>>
>>
>> The problem persists. I cannot write to a file from PHP.
>>
>> Any more suggestions?
>>
>> Thanks.
>>
>> Ethan
>>
>>
>> Hi Ethan,
>>
>> Are you using suPHP or suExec? I believe the server chokes on 777
>> permissions in those cases.
>>
>> Have you checked the permissions in the command line (sorry for the basic
>> question, but just making sure I know what you've already done?)
>>
>> Also, can we see some of the code you're using to handle the file
>> processing?
>>
>> Thanks,
>>
>> Adam
>>
>> --
>> Nephtali: A simple, flexible, fast, and security-focused PHP framework
>> <http://nephtaliproject.com>http://nephtaliproject.com
>>
>
> +++++++++
>
> Adam -
>
> Thanks.
>
> 1] Pardon my ignorance but I do not understand this - Are you using suPHP
>> or suExec?
>>
>
suPHP and suExec are two modules that allow PHP to run with the permissions
of the user, making it easy to write files to disk. However, suPHP (and I
believe suExec, but I can't remember for sure) does not like 777
permissions.
>
> 2] I changed the permissions to 755 and the "Permission Denied" message
> went away.
>
Check!
>
> 3] Have you checked the permissions in the command line? Yes
>
Check!
>
> 4] Here are some code snippets:
>
> $fptr1 = fopen("chessboard", "r+"); //this works
> $fptr2 = fopen('chessboard', 'w'); //this deletes the file, as it should
> for($i = 0; $i <8; $i++)
> {
> for ($j = 0; $j < 8; $j++)
> fprinf($fptr2, "%s ", $results[$i][$j]);
> fprinf($fptr2, "\n");
>
> } //this never writes, so I am left with an empty file
Can you try a simplified form that checks for success along the way? How
about something like the code below to see how far it gets (I haven't
tested, but it should be close):
<?php
// let's make sure you see the E_WARNING errors if present for file
functions
error_reporting(-1);
// set var for later
$cost = 120.89;
if (!($fp = fopen("test.txt", 'w'))) {
echo "Can't open or create file!";
} else if (!($len = fprintf($fp, "In the year 3000, a Coke will cost %01.2f,
with tax.", $cost))) {
echo "Can't write to file!";
} else if (!(fclose($fp))) {
echo "Can't properly close file!";
}
?>
What do you see if you run this?
Adam
--
Nephtali: A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com
+++++++
Thanks.
What do you see if you run this? "Can't open or create file!"
Ethan
--- End Message ---
--- Begin Message ---
On 3/29/2011 3:06 PM, Ethan Rosenberg wrote:
At 01:40 PM 3/29/2011, Adam Richardson wrote:
On Mon, Mar 28, 2011 at 11:43 PM, Ethan Rosenberg <[email protected]>wrote:
> At 11:14 PM 3/28/2011, Adam Richardson wrote:
>
>> On Mon, Mar 28, 2011 at 11:03 PM, Ethan Rosenberg <<mailto:
>> [email protected]>[email protected]> wrote:
>> At 01:32 AM 3/28/2011, Hans �hlin wrote:
>> Do you have SELinux installed?
>>
>> 2011/3/28 Ethan Rosenberg <<mailto:[email protected]>
>> [email protected]>:
>>
>> > Dear List -
>> >
>> > Thanks for all your help in the past. Â Here is another one...
>> >
>> > I am getting a Permission Denied" message when I try to run a PHP
>> script. Â I
>> > just changed the mode on the directory and the files to 777. Â This
>> problem
>> > arose when I changed the permissions. Â I thought I was solving a
>> problem,
>> > because I could not open a file for writing. Â I was not receiving error
>> > messages, but no file was created.
>> >
>> > Help and advice, please.
>> >
>> > Ethan Rosenberg
>> >
>> >
>> >
>> **********************************************
>>  Hans �hlin
>> Â Â Tel: +46761488019
>> Â Â icq: 275232967
>> Â Â <http://www.kronan-net.com/>http://www.kronan-net.com/
>> Â Â irc://<http://irc.freenode.net:6667>irc.freenode.net:6667 - TheCoin
>>
>> **********************************************
>>
>>
>> Hans -
>>
>> Sorry, I did not include my signature, which includes all the requested
>> information.
>>
>> Here it is....
>>
>> Ethan
>> ==========
>> MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)]
>>
>>
>> The problem persists. I cannot write to a file from PHP.
>>
>> Any more suggestions?
>>
>> Thanks.
>>
>> Ethan
>>
>>
>> Hi Ethan,
>>
>> Are you using suPHP or suExec? I believe the server chokes on 777
>> permissions in those cases.
>>
>> Have you checked the permissions in the command line (sorry for the basic
>> question, but just making sure I know what you've already done?)
>>
>> Also, can we see some of the code you're using to handle the file
>> processing?
>>
>> Thanks,
>>
>> Adam
>>
>> --
>> Nephtali: A simple, flexible, fast, and security-focused PHP framework
>> <http://nephtaliproject.com>http://nephtaliproject.com
>>
>
> +++++++++
>
> Adam -
>
> Thanks.
>
> 1] Pardon my ignorance but I do not understand this - Are you using suPHP
>> or suExec?
>>
>
suPHP and suExec are two modules that allow PHP to run with the permissions
of the user, making it easy to write files to disk. However, suPHP (and I
believe suExec, but I can't remember for sure) does not like 777
permissions.
>
> 2] I changed the permissions to 755 and the "Permission Denied" message
> went away.
>
Check!
>
> 3] Have you checked the permissions in the command line? Yes
>
Check!
>
> 4] Here are some code snippets:
>
> $fptr1 = fopen("chessboard", "r+"); //this works
> $fptr2 = fopen('chessboard', 'w'); //this deletes the file, as it should
> for($i = 0; $i <8; $i++)
> {
> for ($j = 0; $j < 8; $j++)
> fprinf($fptr2, "%s ", $results[$i][$j]);
> fprinf($fptr2, "\n");
>
> } //this never writes, so I am left with an empty file
Can you try a simplified form that checks for success along the way? How
about something like the code below to see how far it gets (I haven't
tested, but it should be close):
<?php
// let's make sure you see the E_WARNING errors if present for file
functions
error_reporting(-1);
// set var for later
$cost = 120.89;
if (!($fp = fopen("test.txt", 'w'))) {
echo "Can't open or create file!";
} else if (!($len = fprintf($fp, "In the year 3000, a Coke will cost %01.2f,
with tax.", $cost))) {
echo "Can't write to file!";
} else if (!(fclose($fp))) {
echo "Can't properly close file!";
}
?>
What do you see if you run this?
Adam
--
Nephtali: A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com
+++++++
Thanks.
What do you see if you run this? "Can't open or create file!"
Ethan
Run this. Make certain this script and test.txt are in the same dir. If not, use
full path to your file.
clearstatcache();
$array= stat("test.txt");
print_r($array);//This will tell you what's going on.
Incidentally, consider using file_get_contents() and file_put_contents() Much
easier to use and faster.
--- End Message ---
--- Begin Message ---
At 03:49 PM 3/29/2011, Al wrote:
On 3/29/2011 3:06 PM, Ethan Rosenberg wrote:
At 01:40 PM 3/29/2011, Adam Richardson wrote:
On Mon, Mar 28, 2011 at 11:43 PM, Ethan
Rosenberg <[email protected]>wrote:
> At 11:14 PM 3/28/2011, Adam Richardson wrote:
>
>> On Mon, Mar 28, 2011 at 11:03 PM, Ethan Rosenberg <<mailto:
>> [email protected]>[email protected]> wrote:
>> At 01:32 AM 3/28/2011, Hans �hlin wrote:
>> Do you have SELinux installed?
>>
>> 2011/3/28 Ethan Rosenberg <<mailto:[email protected]>
>> [email protected]>:
>>
>> > Dear List -
>> >
>> > Thanks for all your help in the past. Ã Here is another one...
>> >
>> > I am getting a Permission Denied" message when I try to run a PHP
>> script. Ã I
>> > just changed the mode on the directory and the files to 777. Ã This
>> problem
>> > arose when I changed the permissions. Ã I thought I was solving a
>> problem,
>> > because I could not open a file for
writing. Ã I was not receiving error
>> > messages, but no file was created.
>> >
>> > Help and advice, please.
>> >
>> > Ethan Rosenberg
>> >
>> >
>> >
>> **********************************************
>> à Hans Ã�hlin
>> Ã Ã Tel: +46761488019
>> Ã Ã icq: 275232967
>> Ã Ã <http://www.kronan-net.com/>http://www.kronan-net.com/
>> Ã Ã
irc://<http://irc.freenode.net:6667>irc.freenode.net:6667 - TheCoin
>>
>> **********************************************
>>
>>
>> Hans -
>>
>> Sorry, I did not include my signature, which includes all the requested
>> information.
>>
>> Here it is....
>>
>> Ethan
>> ==========
>> MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)]
>>
>>
>> The problem persists. I cannot write to a file from PHP.
>>
>> Any more suggestions?
>>
>> Thanks.
>>
>> Ethan
>>
>>
>> Hi Ethan,
>>
>> Are you using suPHP or suExec? I believe the server chokes on 777
>> permissions in those cases.
>>
>> Have you checked the permissions in the
command line (sorry for the basic
>> question, but just making sure I know what you've already done?)
>>
>> Also, can we see some of the code you're using to handle the file
>> processing?
>>
>> Thanks,
>>
>> Adam
>>
>> --
>> Nephtali: A simple, flexible, fast, and security-focused PHP framework
>> <http://nephtaliproject.com>http://nephtaliproject.com
>>
>
> +++++++++
>
> Adam -
>
> Thanks.
>
> 1] Pardon my ignorance but I do not understand this - Are you using suPHP
>> or suExec?
>>
>
suPHP and suExec are two modules that allow PHP to run with the permissions
of the user, making it easy to write files to disk. However, suPHP (and I
believe suExec, but I can't remember for sure) does not like 777
permissions.
>
> 2] I changed the permissions to 755 and the "Permission Denied" message
> went away.
>
Check!
>
> 3] Have you checked the permissions in the command line? Yes
>
Check!
>
> 4] Here are some code snippets:
>
> $fptr1 = fopen("chessboard", "r+"); //this works
> $fptr2 = fopen('chessboard', 'w'); //this deletes the file, as it should
> for($i = 0; $i <8; $i++)
> {
> for ($j = 0; $j < 8; $j++)
> fprinf($fptr2, "%s ", $results[$i][$j]);
> fprinf($fptr2, "\n");
>
> } //this never writes, so I am left with an empty file
Can you try a simplified form that checks for success along the way? How
about something like the code below to see how far it gets (I haven't
tested, but it should be close):
<?php
// let's make sure you see the E_WARNING errors if present for file
functions
error_reporting(-1);
// set var for later
$cost = 120.89;
if (!($fp = fopen("test.txt", 'w'))) {
echo "Can't open or create file!";
} else if (!($len = fprintf($fp, "In the year 3000, a Coke will cost %01.2f,
with tax.", $cost))) {
echo "Can't write to file!";
} else if (!(fclose($fp))) {
echo "Can't properly close file!";
}
?>
What do you see if you run this?
Adam
--
Nephtali: A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com
+++++++
Thanks.
What do you see if you run this? "Can't open or create file!"
Ethan
Run this. Make certain this script and test.txt
are in the same dir. If not, use full path to your file.
clearstatcache();
$array= stat("test.txt");
print_r($array);//This will tell you what's going on.
Incidentally, consider using file_get_contents()
and file_put_contents() Much easier to use and faster.
+++++++++++++
Al -
Thanks.
Here is what I ran and the output. I do not know
enough PHP to interpret the output.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
<http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<?php
error_reporting(1);
clearstatcache();
$array= stat("test.txt");
print_r($array);//This will tell you what's going on.
// Output
/* Array ( [0] => 2050 [1] => 876877 [2] => 33188
[3] => 1 [4] => 1001 [5] => 1001 [6] => 0 [7] =>
30 [8] => 1301430589 [9] => 1301430589 [10] =>
1301430589 [11] => 4096 [12] => 8 [dev] => 2050
[ino] => 876877 [mode] => 33188 [nlink] => 1
[uid] => 1001 [gid] => 1001 [rdev] => 0 [size] =>
30 [atime] => 1301430589 [mtime] => 1301430589
[ctime] => 1301430589 [blksize] => 4096 [blocks] => 8 ) */
?>
</body>
</html>
Help and advice, please.
Ethan
--- End Message ---
--- Begin Message ---
Have you checked ownership?
--- End Message ---
--- Begin Message ---
>
> 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
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
On Tue, Mar 29, 2011 at 8:21 PM, Ethan Rosenberg <[email protected]>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
<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
--- End Message ---
--- Begin Message ---
At 3:21 AM +0300 3/29/11, Andre Polykanine wrote:
Hi everyone,
Image processing is a part of Php language completely unknown to me
:-(.
So there is my task: I need to process an uploaded image. We allow
uploading of gif, jpeg, and png images. If an image is wider than
600px, it should be proportionally resized to the width of 600px.
Yes, I've just read about ImageCopyResampled().
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?
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")...
Thanks!
--
With best regards from Ukraine,
Andre
Skype: Francophile
Not that this answers all of your questions, but try this:
http://webbytedd.com/b/thumb/
Cheers,
tedd
--
-------
http://sperling.com/
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
*Anyone have a workaround for this issue? thanks ahead
*I received this error message while activating a profile request.
Clicked the Back button and tried approving the user again and then it
worked.
*
ERROR --------
Using code igniter with DX auth
Description:*
"Deadlock found when trying to get lock; try restarting transaction"
Thanks, T
--- End Message ---
--- Begin Message ---
On Tue, Mar 29, 2011 at 16:38, Tristan <[email protected]> wrote:
> *Anyone have a workaround for this issue? thanks ahead
>
>
> *I received this error message while activating a profile request.
> Clicked the Back button and tried approving the user again and then it
> worked.
> *
>
> ERROR --------
>
> Using code igniter with DX auth
>
> Description:*
> "Deadlock found when trying to get lock; try restarting transaction"
That's anything but a PHP error. You're getting it on CodeIgniter
(framework) code, and it's a MySQL error. Try either of those places,
or the following link:
http://links.parasane.net/f8xf
--
</Daniel P. Brown>
Network Infrastructure Manager
http://www.php.net/
--- End Message ---
--- Begin Message ---
On Tue, 2011-03-29 at 14:38 -0600, Tristan wrote:
> *Anyone have a workaround for this issue? thanks ahead
>
>
> *I received this error message while activating a profile request.
> Clicked the Back button and tried approving the user again and then it
> worked.
> *
>
> ERROR --------
>
> Using code igniter with DX auth
>
> Description:*
> "Deadlock found when trying to get lock; try restarting transaction"
>
>
> Thanks, T
Although CodeIgniter is written in PHP, that's really a question very
specific to CI, and probably best asked on their forums. Going on the
error message, it suggests that it can't modify the DB because something
else has a lock on it. Maybe that will give you a clue?
--
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
On 3/25/2011 12:09 PM, markb wrote:
Very rusty with PHP.
We moved our web site to a new hosting service (godaddy). PHP changed
from 4x to 5.2.17.
I can no longer change $_SESSION variables after the first use.
First call to form - start session create variables
Second call - can read variables, change existing ones (but they do not
persist to next call) - cannot create new variable without an error
Using $_SESSION['varname'] always
session.auto_start off
register_globals off
session.use_only_cookies off
I assume this is setting difference but I can't seem to find it.
OK, here's is what is happening. I think my web hosting service is just
really slow. I am storing the cookies in a unique directory. I create
the directory when I start the session. It appears to take a long time
for the directory creation to occur. The code is posted below. You can
test it at this link: http://www.injection-moldings.com/upload%20test1.php
1. First time you call,
the session starts,
variables assigned to $_SESSION -
but no session ID ([PHPSESSID]) yet
2. Reload the page,
previous $_SESSION data lost
but "markdir" value appears in cookie which is the hash value for the
session path.
Still no session ID
3. Reload -
session ID appears [PHPSESSID]
session data starts saving $_SESSION['test'] will increment
Code:
<?php
ob_start(); //start output buffering
// 10-2007 added java download text to first page
if(!isset($_COOKIE['makedir']) ) {
$unhashdir = startNewSession();
cfinitsession($_SESSION) ;
$_SESSION['mystep'] = 0;
$_SESSION['SUBMIT'] == 'auto';
$_POST = array();
setCookie('pagereload','0',0,'/');
$_COOKIE['pagereload'] = 0;
$_SESSION['pagereload']=0;
echo '<p>starting new session';
} else {
$unhashdir = '';
if (!setupSession1($_COOKIE['makedir'],$unhashdir)) {
die ('Could not start upload session');
exit;
}
$sess = session_start(); //
echo '<p>session running='.$sess;
}
/// hideme
echo '<pre>';
echo '<p>request uri'.$_SERVER['REQUEST_URI'];
if ($_SERVER['REQUEST_METHOD']=="POST") {
$v = print_r($_POST,true);
echo '<p>post:<br>'.$v;
}
$v = print_r($_COOKIE,true);
echo '<p>Cookie:<br>'.$v;
$v = print_r($_SESSION,true);
echo '<p>Session:<br>'.$v;
echo '</pre>';
/// end hideme
if(isset($_COOKIE["PHPSESSID"]))
{
echo '<p></p>session started';
if (isset( $_SESSION['test']) ) {
$_SESSION['test'] ++;
} else {
$_SESSION['test'] =0;
}
}
else
{
echo "<p>no session id";
}
exit;
// **********************************************//
// Functions AND Sub-routines
///////////////////////////////////////////////
// **********************************************//
function setupSession1($mydir,&$plaindir) {
// change the session save directory to our new folder
// $ mydir is encrypted
// $plaindir is unencrypted if available
$rt = false;
if ($plaindir != '' ) {
$mydir = $plaindir;
} else {
$plaindir = 'upload/'.cfFindHashDir($mydir) ;
$mydir = $plaindir;
}
if ($mydir == '') {
$rt = false;
} else {
$tempdir =
$_SERVER['DOCUMENT_ROOT']."/".$mydir.'/tmpZrtg/fe234/dafsksfe' ;
if( !is_dir($tempdir) ) {
Rmkdir($tempdir);
}
if( is_dir($tempdir) ){
ini_set( 'session.save_path',$tempdir );
ini_set('session.gc_maxlifetime',(60*3600*5.0)); //5.0 hours keep
session alive X hours
ini_set('session.gc_probability',1); //never
empty the garbage???
ini_set('session.gc_divisor',1);
}
$rt = is_dir($tempdir);
}
return $rt;
}
function startNewSession() {
$unhashdir = makeSaveDir();
// save SaveDir encrypted
//log_error('New directory ='.$unhashdir);
$newdir =cfSha256($unhashdir); //*&^
//echo '<p>New session started!!:'.$sess." id:".session_id(); //
$_SESSION['SaveDir'] = $newdir;
ini_set("session.use_only_cookies", 0); //do not use cookies
only
ini_set('session.cookie_secure',true);
ini_set('session.use_cookies',0);
setupSession1('',$unhashdir);
$sess = session_start();
setcookie('makedir',$newdir,0,'/');//(time()+(3600*6)),"/");
return $unhashdir;
}
function cfinitvar(&$var,$value) {
if (!isset($var) ) {
$var= $value;
}
}
//function cfinitsession(&$_SESSION) {
function cfinitsession($_SESSION) {
cfinitvar($_SESSION['file_upload_number'],'');
cfinitvar($_SESSION['email_fld'],'');
cfinitvar($_SESSION['first_name_fld'],'');
cfinitvar($_SESSION['position_fld'],'');
cfinitvar($_SESSION['company_fld'],'');
cfinitvar($_SESSION['addr1_fld'],'');
cfinitvar($_SESSION['addr2_fld'],'');
cfinitvar($_SESSION['city_fld'],'');
cfinitvar($_SESSION['state_fld'],'');
cfinitvar($_SESSION['zip_fld'],'');
cfinitvar($_SESSION['country_fld'],'');
cfinitvar($_SESSION['phone_fld'],'');
cfinitvar($_SESSION['fax_fld'],'');
cfinitvar($_SESSION['quote_ref_fld'],'');
cfinitvar($_SESSION['quote_due_fld'],'');
cfinitvar($_SESSION['last_name_fld'],'');
cfinitvar($_SESSION['SaveDir'],'');
cfinitvar($_SESSION['pagereload'],'');
// cfinitvar($_SESSION[''],'');
$_SESSION['mystep'] = intval(0) ;
$_SESSION['SUBMIT'] = 'auto';
$_SESSION['SUBMIT2'] = '';
$_SESSION['goTo'] = '';
$_SESSION['intoverride'] = false;
}
function makeSaveDir() {
$strt = false;
$timestamp = strtotime("now");
$newdir = "upload/$timestamp";
if(!is_dir($newdir)) {
$oldumask = umask();
mkdir($newdir, 0722, true);
umask($oldumask);
}
return $newdir;
}
function cfFindHashDir($dir) {
//$dir is encrypted with cfSha256
$rt = '';
$dirar = cfscandir( PATHTOUPLOAD,true,false) ;
//go backwards through dir names to find it
$f = print_r($dirar,true);
//log_error('dirar'.$f);
//log_error('dirar size'.count($dirar));
//log_error('Dir = '.$dir);
foreach ($dirar as $dirname=>$size) {
//log_error($dirname.'-'.cfSha256($dirname));
if ( cfSha256('upload/'.$dirname) == $dir ) { $rt = $dirname;
break; }
}
return $rt;
}
function cfSha256($data) {
return (base64_encode(bin2hex(mhash(MHASH_SHA256,$data) ) ) );
}
function cfscandir( $dir,$listDirectories=false, $skipDots=true) {
$dirArray = array();
// echo '<P>-- dir='.$dir.'!!<br>';
if (file_exists($dir)) {
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if (($file != "." && $file != "..") || $skipDots == true) {
if($listDirectories == false) {
if(is_dir($dir."/".$file)) { continue ; } }
$dirArray[$file] = filesize($dir.$file) ;
}
}
closedir($handle);
}
}
return $dirArray;
}
function Rmkdir($path){ //recursive make directory
$exp=explode("/",$path);
$way='';
foreach($exp as $n){
$way.=$n.'/';
if(!file_exists($way)) {
// echo "<br>hello<br>making dir:".$way;
// echo "<br>root:".$_SERVER['DOCUMENT_ROOT'];
// echo "<br>self:".$_SERVER["PHP_SELF"];
mkdir($way, 0777);
}
}
}
?>
--
Mark B
--- End Message ---