move() uploaded file does not save the file

Notice: This thread is very old.
richard
Member | 60
+
0
-

I am stuck on this for a while. Why it dumps content of a file but nothing gets uploaded into desired folder? No error.
I am on Xampp Windows, temp_files has full control rights for everyone…
Help is appreciated.

<?php
use Nette\Application\UI\Form;

class HomepagePresenter extends BasePresenter
{
	public function formVerify(Form $form)
	{
	    $file = $form['file']->value;
	    if($file->isOk()) {
		$file->move('/temp_files');
		var_dump($file->getContents());
	    }
	}

	protected function createComponentForm()
	{
	    $form = new Form;
	    $form->addUpload('file', 'File: ');
	    $form->addSubmit('next', 'Next');
	    $form->onSuccess[] = callback($this, 'formVerify');
	    return $form;
	}
}
?>

Last edited by richard (2011-08-10 13:01)

xxxObiWan
Member | 822
+
0
-

Hello, try this if it helps:

$file->move($this->context->params['wwwDir'] . '/temp_files');
richard
Member | 60
+
0
-

My fault.
Parameter is a path to file, not directory.
This works:

<?php
$file->move('/temp_files/file.txt');
?>

Thanks

rixi
Member | 109
+
0
-

It's recommended to use wwwDir param for properly absolute paths in your application. For example if you load web application placed in subfolders, like //localhost/my_application/, etc ..

<?php
$file->move($this->context->params['wwwDir'] . '/temp_files/file.txt');
$file->move($this->context->expand('%wwwDir%/temp_files/file.txt')); // alternative
?>