1
I have a code that sends attachments, I saved it with custom name to find easier later in the database and also to make a more organized backup, but by this fact, it does not save the file extension.
In this part of the code $emailattachment = $_POST['email'].$date = date('_d-m-Y H:i:s');
i would like to add a .$extensao
. How I would do to grab the original file extension, just the extension and add there?
Code send Attachments?
$_UP['pasta'] = '/opt/lampp/htdocs/magento/media/teste/';
$_UP['caminho'] = '/media/teste/';
$_UP['renomeia'] = false;
if(filter_input(INPUT_POST, "btnSubmit")){
if(isset($_POST['email'])){
$emailattachment = $_POST['email'].$date = date('_d-m-Y H:i:s');
}
if ($_UP['renomeia'] == true) {
$nome_final = md5(time()).'.jpg';
} else {
$nome_final = $emailattachment;
}
if (move_uploaded_file($_FILES['attachment']['tmp_name'], $_UP['pasta'] . $nome_final))
Solution
$_UP['pasta'] = '/opt/lampp/htdocs/magento/media/teste/';
$_UP['caminho'] = '/media/teste/';
$_UP['renomeia'] = true;
if(filter_input(INPUT_POST, "btnSubmit")){
$path = $_FILES['attachment']['name'];
$extensao = pathinfo($path, PATHINFO_EXTENSION);
$emailattachment = $_POST['email'] . $date = date('_d-m-Y_H-i-s') .'.'. $extensao;
if ($_UP['renomeia'] == true) {
$nome_final = $emailattachment;
}
if (move_uploaded_file($_FILES['attachment']['tmp_name'], $_UP['pasta'] . $nome_final)) {
$connection = Mage::getSingleton('core/resource')->getConnection('core_write');
$query = "INSERT INTO contato (`nome`,`caminho`) VALUES ('".$nome_final."', '".$_UP['pasta']."')";
$connection->query($query);
}
It worked, but I had to edit it, some things weren’t "right"
– Gustavo Souza
@Gustavosouza Post your functional code then, should help others.
– phzao
I put it there in my question, "Solution".
– Gustavo Souza