So my problem is: I have an 'uploading file' section where I upload files with this format: Author - Title of the file.doc.
I use explode(" - ", $string) to split the file name into pieces and save it in a db. That's working fine so far but when I upload files and its name contains any special characters, the file doesn't get saved with the original name+special characters in the server. It does in the db. (Eew, I hope you guys understand this part).
I'll paste my file.php class here:
Code: Select all
<?php
/* file.php */
Class File
{
/* MEMBER DATA */
private $db;
/* CONSTRUCTOR */
public function File($db)
{
$this->db= $db;
}
/* BEHAVIORS */
public function UploadFile()
{
if (isset($_POST['upload']))
{
$extension= explode(".", $_FILES['file']['name']);
if ($extension[1] != "doc")
{
die ("La extension del archivo no es valida.");
}
else
{
$path= "files/";
$path= $path. basename($_FILES['file']['name']);
if (move_uploaded_file($_FILES['file']['tmp_name'],$path))
{
$author= explode(" - ",$_FILES['file']['name']);
$title= explode(".",$author[1]);
$title2= explode(".",$title);
$date= time();
$sql= "INSERT INTO archivos (author, title, type, date) VALUES (%s, %s, %s, %d)";
$vars= array($author[0],$title[0],$_POST['type'],$date);
$result= $this->db->query($sql, $vars) or die ("ERROR");
die ("El archivo ha sido guardado exitosamente.");
}
else
{
die ("Ha habido un error al subir el archivo. Intente mas tarde.");
}
}
}
}
}
?>I know most of you won't understand this because you're main language is english. But any help is welcomed.