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
Shell_Exec() Timeout Management & Exec()
PHP Require_Once Failed to Open Stream Permission Denied
Strpos() with Multiple Needles
Getting PHP to Run a Python Script
Mysqli Query to Loop Through Array and Update Multiple Rows
Follow Redirects with Curl in PHP
"Transfer-Encoding: Chunked" Header in PHP
Phalcon Performance Related Queries
What's the Best and Easiest Way to Populate a Dropdown Based on Another Dropdown
Macd Function Returning Incorrect Values
Php: How to Add Leading Zeros/Zero Padding to Float via Sprintf()
Php: How to Check If the Client Is Local
Utf-8 Characters in Preg_Match_All (Php)
Indented List to Multidimensional Array
Filter_Sanitize VS Filter Validate, Whats the Difference - and Which to Use