Ask a Question related to PHP Development, Design and Development.
-
mmsnork #1
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
-
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... -
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... -
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... -
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... -
what is the difference....
Hi, What is the difference between.... $data = file($this->URL); ....and... $data = @file($this->URL); -
Andy Hassall #2
Re: I don't get it. What's the difference??
On Thu, 22 Apr 2004 22:03:58 GMT, Pygar <pygar@spamcop.net> wrote:
Actually I don't know off the top of my head what happens now. You have a>"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:
>> global $dest;>>#2:
>><?php
>>function uploadFile($dest)
>>{
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.
In #1 you use $_FILES['userfile']['tmp_name'].>> $dest = "$dest" . $_FILES['userfile']['name'] ;
>> move_uploaded_file($_FILES['userfile']['name'], $dest);
In #2 you use $_FILES['userfile']['name'].
move_uploaded_file requires the 'tmp_name', not the 'name'.
The OP was already passing the value as a parameter properly, rather than>>>}
>>
>>$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.
"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
-
mmsnork #3
Re: I don't get it. What's the difference??
> In #1 you use $_FILES['userfile']['tmp_name'].
That's it. It was very stupid of me. Thanks Andy.> In #2 you use $_FILES['userfile']['name'].
Mike
mmsnork Guest



Reply With Quote

