jafakash cp Posted July 6, 2017 Share Posted July 6, 2017 (edited) hi, am working on prestashop 1.7 . i made a tpl file with form to upload image . when button submit i will move upload image to an image folder and call email functionality to add attachment , my email functionality is working fine but in controller (i have added my own controller) i cant move image to a particular folder. my code to move uploaded file is given below. ****************************************************************************************************** if (isset($_FILES['fileUpload']['name']) && !empty($_FILES['fileUpload']['name']) && !empty($_FILES['fileUpload']['tmp_name'])) { $move =$url.__PS_BASE_URI__.'/img/'; //echo __PS_BASE_URI__;die; $uploadedFile = $_FILES['fileUpload']['tmp_name']; if(move_uploaded_file($uploadedFile, $url.__PS_BASE_URI__.'/img/'.$_FILES["fileUpload"]["name"])) { chmod($move, 0755); echo "upload complete";die; } else{echo " 1error";die;} echo dirname(__FILE__).'';die; } ************************************************************************************************************************** function never entering in if(move_uploaded_file($uploadedFile, $url.__PS_BASE_URI__.'/img/'.$_FILES["fileUpload"]["name"])) this condition , always going to else condition. please let me know is there any issue in my code or how to resolve this issue. waiting for your valuable reply Edited July 6, 2017 by jafakash cp (see edit history) Link to comment Share on other sites More sharing options...
jafakash cp Posted July 11, 2017 Author Share Posted July 11, 2017 i hope i will get replay from any prestashop expertise as soon as possible ...... waiting for your valuable reply Link to comment Share on other sites More sharing options...
Darani Posted July 18, 2023 Share Posted July 18, 2023 I want to upload my file and I want to save the name of the file into database and the file should be moved to the local directory. Link to comment Share on other sites More sharing options...
Darani Posted July 19, 2023 Share Posted July 19, 2023 public function fileUpload($uploadFile){ $fileName=$_FILES['image']['name']; $temp_file = $_FILES['image']['tmp_name']; $image_path = dirname(__DIR__)."\sp_banner\images\\".$_FILES['image']['name']; if (move_uploaded_file($temp_file, $image_path)) { $output = $this->displayConfirmation($this->l(' File uploaded successfully')); return $fileName; } else { $output = $this->displayError($this->l('Error in uploading file')); } } $insertData = array( 'name_slide' => $slidername, 'link' => $link, 'position' => $position, 'active' => $status, 'image' => $uploadFile, ); Link to comment Share on other sites More sharing options...
AddWeb Solution Posted July 20, 2023 Share Posted July 20, 2023 Hi, It's essential to sanitize the file name. Remove any characters that are not allowed or could cause issues in file names. Instead of using backslashes (\) or forward slashes (/) directly in the file path, use DIRECTORY_SEPARATOR constant for better portability across different operating systems. $fileName = preg_replace('/[^A-Za-z0-9_\-\.]/', '', $fileName); // Sanitize the file name $image_path = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'sp_banner' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . $fileName; Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now