php-general Digest 15 Oct 2011 14:01:51 -0000 Issue 7521

2011-10-15 Thread php-general-digest-help

php-general Digest 15 Oct 2011 14:01:51 - Issue 7521

Topics (messages 315306 through 315313):

Re: Processing newlines in a text area field
315306 by: Stephen

move_uploaded_file() does not return any value or warning
315307 by: Partha Chowdhury
315308 by: Simon J Welsh
315309 by: Partha Chowdhury

Re: Dennis Ritchie, Father of Unix and C programming language, dead at 70
315310 by: Ricardo Martinez
315311 by: Arno Kuhl
315312 by: shiplu

Extending an instantiated class
315313 by: Alain Williams

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---

On 11-10-13 10:49 PM, Stephen wrote:

I have a web page with a form with a text area. I enter:

foo


bar

PHP processes the POST and inserts the record into MySQL.

The database field is text.

I use PDO

For testing I have removed any processing of the text area content.

Now, no matter how many blank rows I have between foo and bar, in the 
database record, I always get a single newline character.


Found the problem. I was not passing the record key properly to the SQL 
UPDATE transaction.


So I had WHERE id = 

Valid SQL so no error. But no record update :(

Thanks all
Stephen
---End Message---
---BeginMessage---

Hello List.

I am learning php and MySQL for my project work.

I am trying to upload files to local server.

First, a page is displayed on the browser to upload file

Relevant code:


form method=post action=index.php enctype=multipart/form-data
input type=file name=file
br
input type=submit name=submit value=upload
/form
After the user chooses a file and hit the submit button,the browser 
displays the content from the uploads directory.


Php code:


?php
 if (isset ($_POST['submit'])  ($_POST['submit']==upload)) {
$pathname = uploads;
if (!file_exists($pathname)) {
$mkdir = mkdir($pathname);
if (!$mkdir) {
echo 'could not create directory uploads/';
exit();
}
}
$filename = $_FILES['file']['tmp_name'];
$destination = uploads/ . time() . _- . 
$_FILES['file']['name'];



  move_uploaded_file($filename, $destination);
header(Location:uploads/);

But the uploads directory is empty and no warning or error is displayed !

Then i set a check for the return value of move-uploaded_file.

if(isset ($move_uploaded_file)):
   echo success;
   else:
   echo error in uploading;
   endif;

But it does not print anything ! .According to manual,


Returns *TRUE* on success.

If /filename/ is not a valid upload file, then no action will occur, 
and *move_uploaded_file()* will return *FALSE*.


If /filename/ is a valid upload file, but cannot be moved for some 
reason, no action will occur, and *move_uploaded_file()* will return 
*FALSE*. Additionally, a warning will be issued.



So the above code should have printed error in uploading.
Then i tried the copy() function and it prints a warning:

*Warning*: copy() [function.copy 
http://localhost/file_uploading/function.copy]: Filename cannot be 
empty in */srv/www/htdocs/file_uploading/index.php* on line *38*

line 38 is


copy($filename, $destination);
Then i did a print_r($_FILES['file']) and found that 
$_FILES['file']['error'] was 1 .The problem was the file i was trying to 
upload was 6M in size,greater than upload_max_filesize in /etc/php.ini 
which was 2M.I changed that and now it works.


So I want to know - does move_uploaded_file returns false on failure or 
is there a bug in my code ?


I am using php 5.3.8 which is configured with

'./configure' '--prefix=/php' '--with-apxs2=/apache/bin/apxs' 
'--with-config-file-path=/etc' '--with-mysql-sock=/tmp/mysql.sock' 
'--with-openssl' '--with-zlib' '--enable-bcmath' '--with-bz2' 
'--enable-calendar' '--with-gdbm' '--with-enchant' '--enable-exif' 
'--enable-ftp' '--with-gd' '--enable-gd-native-ttf' '--with-gettext' 
'--with-gmp' '--enable-mbstring' '--with-mcrypt' '--with-readline' 
'--enable-soap' '--enable-sqlite-utf8' '--enable-zip' 
'--with-mysql=mysqlnd' '--with-mysqli=mysqlnd' 
'--with-jpeg-dir=/usr/lib' '--with-freetype-dir'
and error_reporting directive in php.ini is error_reporting = E_ALL | 
E_STRICT.


---End Message---
---BeginMessage---
On 15/10/2011, at 4:01 PM, Partha Chowdhury wrote:

 Then i set a check for the return value of move-uploaded_file.
 if(isset ($move_uploaded_file)):
   echo success;
   else:
   echo error in uploading;
   endif;
 But it does not print anything !

Assuming you did $move_uploaded_file = 

Re: [PHP] Dennis Ritchie, Father of Unix and C programming language, dead at 70

2011-10-15 Thread Ricardo Martinez
int main()
{
   printf(R.I.P. Dennis Ritchie: 1941-2011\n);
   return 0
}


sad notice...  RIP




On Fri, Oct 14, 2011 at 10:01 PM, tamouse mailing lists 
tamouse.li...@gmail.com wrote:

 On Thu, Oct 13, 2011 at 5:08 PM, Daevid Vincent dae...@daevid.com wrote:
  #include stdio.h
 
  int main()
  {
printf(R.I.P. Dennis Ritchie: 1941-2011\n);
return 0;
  }
 
 
  http://www.networkworld.com/news/2011/101311-ritchie-251936.html
 
 

 dmr--; /* :-( */

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




-- 
Ricardo
___
IT Architect
website: http://www.pulsarinara.com


RE: [PHP] Dennis Ritchie, Father of Unix and C programming language, dead at 70

2011-10-15 Thread Arno Kuhl
-Original Message-
From: Daevid Vincent [mailto:dae...@daevid.com] 
Sent: 14 October 2011 12:08 AM
To: php-general@lists.php.net
Subject: [PHP] Dennis Ritchie, Father of Unix and C programming language,
dead at 70

#include stdio.h
 
int main()
{
   printf(R.I.P. Dennis Ritchie: 1941-2011\n);
   return 0;
}
 
http://www.networkworld.com/news/2011/101311-ritchie-251936.html

===

He might have put it a bit differently:

int main()
{
   printf(Goodbye world\n);
   return 0;
} 



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



Re: [PHP] Dennis Ritchie, Father of Unix and C programming language, dead at 70

2011-10-15 Thread shiplu
I found this, And I liked it.

int main()
{
printf(Goodbye Daddy\n);
return 0;
}


-- 
Shiplu Mokadd.im
Follow me, http://twitter.com/shiplu
Innovation distinguishes between follower and leader


[PHP] Extending an instantiated class

2011-10-15 Thread Alain Williams
Well, that is what I think that I need. Please let me explain what I am trying 
to do
and tell me how to do it or a better way of doing it.

I have an application where a Screen (web page) may contain several Forms. The 
Forms
will want to access properties, etc, from their Screen. So what I want is to do
something like:

class Screen {
private $JavascriptVars = array();

function AddJsVar($name, $val) {
  $this-JavascriptVars[$name] = $val;
}
}

class Form extends Screen {
public $screen;  // Could set to a class Screen

function DefineForm($fName)
.
}

$s = new Screen();
$s-AddJsVar('Date', '15 Oct 2011');

$f1 = new Form($s);
$f1-DefineForm('search');
$f1-AddJsVar('CompanyName', 'IBM');

$f2 = new Form($s);
$f2-DefineForm('login');
$f2-AddJsVar('Error', 'Login failed');

The trouble is that $f1-AddJsVar() will fail, class extention seems not 
designed to work like that.

I could make it work by either:

1) $f1-screen-AddJsVar() --- but I would rather avoid the extra '-screen'.

2) Use of a __call() in class Form -- but that makes things slower.


Any help gratefully received.



I think that to do what I want PHP would need a syntax like:

$f2 = new $s Form();
or
$f2 = $s-new Form();

-- 
Alain Williams
Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT 
Lecturer.
+44 (0) 787 668 0256  http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: 
http://www.phcomp.co.uk/contact.php
#include std_disclaimer.h

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



[PHP] Image Rotation Script

2011-10-15 Thread dev
We have a simple script which rotates and image to a random value, saves
it to a cache directory and displays it. For some reason when I move the
script from a Debian box over to the production CentOS machine, it no
longer caches any of the images. the rest works, but not the cache. If you
could look at it and see if anything jumps out at you, please let me know.

install the code below to the directory /angles


.htaccess:
RewriteEngine on
RewriteRule ^rotate_(\d+)(?:_(?:\d+))?.png$ rotate.php?im=$1

rotate.php:
?php
// Setup
if(isset($_GET['im'])  file_exists($_GET['im'].'.png')) {
header('Content-type: image/png');
$im = $_GET['im'].'.png';
$degrees = rand(0, 360);
$save = 'cache/'.$_GET['im'].'_'.$degrees.'.png';
if(!file_exists($save)) {
// Rotate via command line and cache it
exec('convert '.$im.' -filter \'Lanczos\' -resize \'150x150\' -rotate
'.$degrees.' -black-threshold 40% '.$save, $out);
}
// Output out (newly?) cached file
echo file_get_contents($save);
} else {
die(Image not found);
}
?

Use it by url:
http://www.servername.com/angles/rotate_019.png
Each time you reload page the angle should rotate to a new position.
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] Image Rotation Script

2011-10-15 Thread Stuart Dallas
On 15 Oct 2011, at 15:50, d...@nkmo.com wrote:

 We have a simple script which rotates and image to a random value, saves
 it to a cache directory and displays it. For some reason when I move the
 script from a Debian box over to the production CentOS machine, it no
 longer caches any of the images. the rest works, but not the cache. If you
 could look at it and see if anything jumps out at you, please let me know.
 
 install the code below to the directory /angles
 
 
 .htaccess:
 RewriteEngine on
 RewriteRule ^rotate_(\d+)(?:_(?:\d+))?.png$ rotate.php?im=$1
 
 rotate.php:
 ?php
 // Setup
 if(isset($_GET['im'])  file_exists($_GET['im'].'.png')) {
 header('Content-type: image/png');
 $im = $_GET['im'].'.png';
 $degrees = rand(0, 360);
 $save = 'cache/'.$_GET['im'].'_'.$degrees.'.png';
 if(!file_exists($save)) {
 // Rotate via command line and cache it
 exec('convert '.$im.' -filter \'Lanczos\' -resize \'150x150\' -rotate
 '.$degrees.' -black-threshold 40% '.$save, $out);
 }
 // Output out (newly?) cached file
 echo file_get_contents($save);
 } else {
 die(Image not found);
 }
 ?
 
 Use it by url:
 http://www.servername.com/angles/rotate_019.png
 Each time you reload page the angle should rotate to a new position.

My first thought was that the current working directory is probably set 
differently. However, you say that the script works and presents the rotated 
images, it's just the cache that isn't right. I still think I'm probably 
correct, so try these changes...

 $im = dirname(__FILE__).'/'.$_GET['im'].'.png';


and...

 $save = dirname(__FILE__).'/cache/'.$_GET['im'].'_'.$degrees.'.png';

You also have a pretty major hole here because you're taking a querystring 
parameter and putting it straight into a command line. What happens if I pass 
the value of $_GET['im'] as ../../../../../../../../../../../etc/passwd ? Use 
escapeshellarg when putting variables into command lines to protect against 
this type of hack.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/


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



[PHP] Re: Extending an instantiated class

2011-10-15 Thread Alain Williams
On Sat, Oct 15, 2011 at 03:01:44PM +0100, Alain Williams wrote:
 Well, that is what I think that I need. Please let me explain what I am 
 trying to do
 and tell me how to do it or a better way of doing it.
 ..

I have solved it. The problem is basically one of ensuring that properties are 
the same
value when accessed via the parent or child class ... be that to get or set a 
value.
So I solved the problem by making the properties in the child class references 
to the
ones in the parent class.

Methods are not a problem - inheritance just works fine.

To do this, pass the instance of the parent class to the child class 
constructor and use
a reflection class to determine the properties in the parent class. This will 
not work
properly if the child class overrides a property of the parent class ... this 
does not
worry me.

class Screen {
public $screen;

}

class Form extends Screen {
function __construct($s) {
  $sr = new ReflectionClass($s);

  foreach($sr-getProperties(ReflectionProperty::IS_PUBLIC | 
ReflectionProperty::IS_PROTECTED) as $p)
$this-{$p-name} = $s-{$p-name};
}
}

$s = new Screen();
$s-AddJsVar('Date', '15 Oct 2011');

$f1 = new Form($s);

$f1-screen = 'something'; // this assigns the property in $s.


Comments ?

-- 
Alain Williams
Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT 
Lecturer.
+44 (0) 787 668 0256  http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: 
http://www.phcomp.co.uk/contact.php
#include std_disclaimer.h

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



[PHP] Seeking strategy/algorithm for maintaining order of records

2011-10-15 Thread Stephen

I am building a site for my photography.

The photographs are displayed by category.

The category table has a field for order

In my control panel I want to be able to change the order of the 
categories by changing the values in the category field.


I can dynamically build a form of all categories and have a field for 
new order number,  Then loop through the POST and update the values.


The field is not unique, so I am not worried about DB errors.

But I wonder if there is a better way.

Thoughts please?

Thank you
Stephen

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