php-general Digest 15 Oct 2011 14:01:51 -0000 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


----------------------------------------------------------------------
--- Begin Message ---
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 ---
--- Begin Message ---
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 ---
--- Begin Message ---
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 = move_uploaded_file($filename, 
$destination);, then isset($move_uploaded_file) will always be true.

isset() just checks if the variable you past to it is set, not if it has a 
non-false value. You could simply use if(move_uploaded_file($filename, 
$destination)), or if($move_uploaded_file).
---
Simon Welsh
Admin of http://simon.geek.nz/


--- End Message ---
--- Begin Message ---
On 15/10/11 08:35 AM, Simon J Welsh wrote:
Assuming you did $move_uploaded_file = move_uploaded_file($filename, $destination);, then isset($move_uploaded_file) will always be true. isset() just checks if the variable you past to it is set, not if it has a non-false value. You could simply use if(move_uploaded_file($filename, $destination)), or if($move_uploaded_file).
My apologies - i forgot to include the $move_uploaded_file = move_uploaded_file($filename, $destination); line.

I saw in the manual that isset() "isset --- Determine if a variable is set and is not NULL" and thought if move_uploaded_file() returns false, the error checking will be triggered.But now i see the sample code in the manual and stand corrected.

So what was happening that $move_uploaded_file was set but empty.My understanding of isset() was wrong.

*
*




--- End Message ---
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
-----Original Message-----
From: Daevid Vincent [mailto:dae...@daevid.com] 
Sent: 14 October 2011 12:08 AM
To: php-gene...@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;
} 



--- End Message ---
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
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>

--- End Message ---

Reply via email to