Professional Web Applications Themes

I don't get it. What's the difference?? - PHP Development

Why does #1 below works but not #2? The only difference is that I'm calling move_uploaded_file() from within a function. Thanks in advance. Mike #1: <?php $dest = "./images/"; $dest = $dest . $_FILES['userfile']['name'] ; move_uploaded_file($_FILES['userfile']['tmp_name'], $dest) ; ?> ================================================== = #2: <?php function uploadFile($dest) { $dest = "$dest" . $_FILES['userfile']['name'] ; move_uploaded_file($_FILES['userfile']['name'], $dest); } $destDir = "./images/"; uploadFile($destDir) ; ?>...

  1. #1

    Default I don't get it. What's the difference??

    Why does #1 below works but not #2? The only difference is that I'm calling
    move_uploaded_file() from within a function. Thanks in advance.

    Mike

    #1:
    <?php
    $dest = "./images/";
    $dest = $dest . $_FILES['userfile']['name'] ;
    move_uploaded_file($_FILES['userfile']['tmp_name'], $dest) ;
    ?>
    ================================================== =
    #2:
    <?php
    function uploadFile($dest)
    {
    $dest = "$dest" . $_FILES['userfile']['name'] ;
    move_uploaded_file($_FILES['userfile']['name'], $dest);
    }

    $destDir = "./images/";
    uploadFile($destDir) ;
    ?>


    mmsnork Guest

  2. #2

    Default Re: I don't get it. What's the difference??

    On Thu, 22 Apr 2004 22:03:58 GMT, Pygar <pygarspamcop.net> wrote:
    >"mmsnork" <nospam9comcast.net> wrote:
    >
    >>Why does #1 below works but not #2? The only difference is that I'm calling
    >>move_uploaded_file() from within a function. Thanks in advance.
    >>
    >>Mike
    >>
    >>#1:
    >><?php
    >> $dest = "./images/";
    >> $dest = $dest . $_FILES['userfile']['name'] ;
    >> move_uploaded_file($_FILES['userfile']['tmp_name'], $dest) ;
    >>?>
    >>================================================ ===
    >
    >I believe in #2 you need to add one line:
    >
    >>#2:
    >><?php
    >>function uploadFile($dest)
    >>{
    > global $dest;
    Actually I don't know off the top of my head what happens now. You have a
    local paramter named $dest, and you've just used global $dest. I presume this
    brings the global $dest into scope and hides the local parameter? Which
    wouldn't be what the OP wants at all in #2, since there isn't a global $dest.
    >> $dest = "$dest" . $_FILES['userfile']['name'] ;
    >> move_uploaded_file($_FILES['userfile']['name'], $dest);
    In #1 you use $_FILES['userfile']['tmp_name'].
    In #2 you use $_FILES['userfile']['name'].

    move_uploaded_file requires the 'tmp_name', not the 'name'.
    >>}
    >>
    >>$destDir = "./images/";
    >>uploadFile($destDir) ;
    >>?>
    >>
    >
    >Variable scope is different in PHP than in something like Javascript.
    >In order to "pass" a value, you may have to declare it as a global.
    The OP was already passing the value as a parameter properly, rather than
    "passing" it through a global.

    --
    Andy Hassall <andyandyh.co.uk> / Space: disk usage ysis tool
    [url]http://www.andyh.co.uk[/url] / [url]http://www.andyhsoftware.co.uk/space[/url]
    Andy Hassall Guest

  3. #3

    Default Re: I don't get it. What's the difference??

    > In #1 you use $_FILES['userfile']['tmp_name'].
    > In #2 you use $_FILES['userfile']['name'].
    That's it. It was very stupid of me. Thanks Andy.

    Mike


    mmsnork Guest

Similar Threads

  1. what's the difference?
    By wrrn in forum Macromedia Dreamweaver
    Replies: 9
    Last Post: December 4th, 02:09 AM
  2. difference
    By SMITTY in forum Macromedia Flex General Discussion
    Replies: 2
    Last Post: November 28th, 09:42 PM
  3. difference between these 2?
    By Jay in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: September 20th, 07:28 AM
  4. what is the difference....
    By Disco in forum PHP Development
    Replies: 1
    Last Post: September 4th, 07:39 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139