You are here: Re: uploading a document and moving to a subfolder « All PHP « IT news, forums, messages
Re: uploading a document and moving to a subfolder

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация