1
help me with this code here in PHP:
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>Atualização de dados</title>
<link rel="stylesheet" type="text/css" href="upload.css"/>
<link href='https://fonts.googleapis.com/css?family=Varela+Round|Raleway:900' rel='stylesheet' type='text/css'>
<script type:"text/javascript" src="../jquery-2.1.4.min.js"></script>
</head>
<body>
<div><p id="header"><b>ATUALIZAÇÃO DE CONTEÚDO</b></p></div>
<?php
ini_set('default_charset','UTF-8');
require("../dbconnect.inc.php");
$assunto = isset($_POST['ass']) ? $_POST['ass'] : FALSE;
$aula = isset($_POST['aul']) ? $_POST['aul'] : FALSE;
$qURL = isset($_POST['qURL']) ? $_POST['qURL'] : FALSE;
$vid_nome = $_FILES['vidUpdt']['name'];
$aud_nome = $_FILES['audUpdt']['name'];
$img_nome = $_FILES['imgUpdt']['name'];
$txt_nome = $_FILES['txtUpdt']['name'];
//Diretórios raíz de uma aula
$_UPAul['pasta']['video'] = 'video/' . $assunto . '/' . $aula;
$_UPAul['pasta']['audio'] = 'audio/' . $assunto . '/' . $aula;
$_UPAul['pasta']['texto'] = 'texto/' . $assunto . '/' . $aula;
$_UPAul['pasta']['imagem'] = 'imagem/' . $assunto . '/' . $aula;
//UPDATE DO VIDEO
if(empty($vid_nome)==FALSE){
ExcluiDir($_UPAul['pasta']['video']);
if(!(file_exists('video/' . $assunto))){
mkdir('video/' . $assunto . '/' . $aula,0777,true);
}else{
mkdir('video/' . $assunto . '/' . $aula,0777);
}
$_UP['pasta']['video'] = 'video/' . $assunto . '/' . $aula . '/';
$vid_URL = $_UP['pasta']['video'] . $vid_nome;
if (move_uploaded_file($_FILES['vidUpdt']['tmp_name'], $_UP['pasta']['video'] . $vid_nome)) {
// Upload efetuado com sucesso, exibe uma mensagem e um link para o arquivo
echo "<p align='center' style='color:#8F8F8F'>Upload do video efetuado com sucesso!</p>";
} else {
// Não foi possível fazer o upload, provavelmente a pasta está incorreta
echo "<p align='center' style='color:#8F8F8F'>Não foi possível enviar o arquivo de video, tente novamente.</p> <br>";
}
}
?>
What is going on: The file name sent from the client to the server is stored correctly in the Mysql database, but when creating the file in the specified directory, the file gets several special characters displayed in the wrong way, what causes faults in the file call when this is requested by the client side.
I already put all the files in the UTF-8 encoding. How can I solve this?
Do not use special characters in file names. It is the best way to fix your problem.
– Marcos Regis
I make this recommendation to the user at the instant of inserting the files. But I wonder if you have how to get around the problem in a simple way without having to give this kind of concern to the user.
– Jack Jibbers
@user3450942 if it uploads by the application itself, it is the case of sanitizing the names before saving, exchanging special and accented characters for an ASCII equivalent. If in the future it is going to download through the application, you can even save the original DB name, so it does not lose anything. Depending on the case, just convert the name to Base64, which solves. Just watch out for the overhead in the name size. In fact, if you save the original file name to a DB, you can use the database ID itself for the file name. file0000001, file000002 etc.
– Bacco
As long as the sizes of the names do not exceed 75% of the capacity of the filesystem, that’s all it takes:
$convertido= strtr(base64_encode($original), '+/', '-_');
and$original = base64_decode(strtr($convertido, '-_', '+/'));
– Bacco