Destination Path for Move_Uploaded_File in PHP

destination path for move_uploaded_file in php

You should use document_root to get absolute path like this:

$target_path = $_SERVER['DOCUMENT_ROOT'] . "/uploads/" . basename($_FILES['uploadedFile']['name']);

How to create destination (Folder) in PHP while using move_uploaded_file()?

Use mkdir().

If you need to make multiple folders, such as by passing a/b/c, set the third argument to TRUE.

You can test if it is already there, and add if not like so....

$path = 'abc';

if ( ! is_dir($path)) {
mkdir($path);
}

PHP move_uploaded_file multiple paths

Try the following:

if(move_uploaded_file($tmp, $new_dest)){
//moved to destination, now copy
copy($new_dest, $another_new_dest);
}

if you need it to copy to more then one other

if(move_uploaded_file($tmp, $new_dest)){
//moved to destination, now copy
copy($new_dest, $another_new_dest);
copy($new_dest, $yet_another_new_dest);
//and so on...
}

PHP define the destination folder for an upload

You will need to check if the destination folder exists.

$destination = $_SERVER['DOCUMENT_ROOT'] . '/imageUploads/'

if (! file_exists($destination)) { // if not exists
mkdir($destination, 0777, true); // create folder with read/write permission.
}

And then try to move the file

$filename = $_FILES["file-upload"]["name"];
move_uploaded_file($source, $destination . $filename);

move_uploaded_file saves on wrong destination

Try to use directory separator (DS) in your paths :

if ($this->request->is(['patch', 'post', 'put'])){
$nameImg = $this->request->getData('imagem.name');
$imgTmp = $this->request->getData('imagem.tmp_name');

$destination = WWW_ROOT . 'files' . DS . 'user' . DS . $user_id . DS . $nameImg;

if(move_uploaded_file($imgTmp, $destination)){
$this->Flash->success(__('Success!'));
}
}

PHP move_uploaded_file local path

Here is the definition:
bool move_uploaded_file ( string $filename , string $destination )

In $destination you can put any valid path.
Be sure the directory security allows for writing for the user that webserver runs as.



Related Topics



Leave a reply



Submit