|
Posted by Rik on 07/13/06 09:25
Christina wrote:
> Hi,
>
> Yes, I already understood the part of it initially being put into a
> temp directory, what I don't understand is that every tutorial I see
> has the move_uploaded_file($_FILES['uploadedfile']['tmp_name'],
> $target_path) inside an if statement. "if
> (move_uploaded_file($_FILES['uploadedfile']['tmp_name']$target_path)
> )" rather than as a command or call to a function. Therefore it
> seems to me it is just check if the file was moved, and if so, you do
> something within the if statement. So, do you need to state:
> "move_uploaded_file($_FILES['uploadedfile']['tmp_name']$target_path);",
> then do the if statement: "if
> (move_uploaded_file($_FILES['uploadedfile']['tmp_name']$target_path)
> )"?
Look at the manuel:
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,
if(move_uploaded_file($tmp,$target)){
//will execute code on succes: succesfull upload & move.
} else {
//error with moving or uploading
}
The following will work, but more verbose:
$checkj = move_uploaded_file($tmp,$target);
if($check){
//will execute code on succes: succesfull upload & move.
} else {
//error with moving or uploading
}
The following will not work, because the file already has been moved:
move_uploaded_file($tmp,$target); //this works
if(move_uploaded_file($tmp,$target)){ // this returns false: the file has
already been moved
//will execute code on succes: succesfull upload & move.
} else {
//error with moving or uploading
}
Grtz,
--
Rik Wasmus
Navigation:
[Reply to this message]
|