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

Ask a Question related to PHP Development, Design and Development.

  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. Similar Questions and Discussions

    1. what's the difference?
      Greetings - I'm looking to buy a good beginners book on DMX/php/mysql and I see this one mentioned all over the place, but I also hear complaints...
    2. Why is there a difference??
      I'm noticing that for some reason the 2 icons I have on my page are moving in different browsers. Look fine in IE but not in Firefox. Page is...
    3. difference between these 2?
      In some examples I am looking through they are speaking of datagrids and datalists (this is not the question :) For the datalist a column is...
    4. Difference between ASP & PHP
      I doubt about the difference between ASP & PHP. Some people say that PHP is faster than ASP and PHP is the free equivalant of ASP. An other...
    5. what is the difference....
      Hi, What is the difference between.... $data = file($this->URL); ....and... $data = @file($this->URL);
  3. #2

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

    On Thu, 22 Apr 2004 22:03:58 GMT, Pygar <pygar@spamcop.net> wrote:
    >"mmsnork" <nospam9@comcast.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 <andy@andyh.co.uk> / Space: disk usage analysis tool
    [url]http://www.andyh.co.uk[/url] / [url]http://www.andyhsoftware.co.uk/space[/url]
    Andy Hassall Guest

  4. #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

Posting Permissions

  • You may not post new threads
  • You may 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