ODSKOK JINDE
php file upload funkce
Kategorie: linux
$url="http://localhost/f/";
if( file_exists($_FILES["fileToUpload"]['tmp_name'] ))
{
$j=iconv("utf-8", "us-ascii//TRANSLIT", $_FILES["fileToUpload"]['name']);
$j=str_replace(' ', '-', $j);
$j=substr($j, 0, 20);
$jmeno_obr=$j;
// $jmeno_obr=uniqid();
$imageFileType = strtolower(pathinfo($_FILES["fileToUpload"]["name"],PATHINFO_EXTENSION));
if (nahrej_obr("fileToUpload",$jmeno_obr))
{
$odkazy .="".$jmeno_obr.".".$imageFileType." ";
echo $odkazy;
}
}
////////////////// FUNKCE NAHREJ_OBR //////////////////////
//
// $target_name - bez pripony
////////////////
function nahrej_obr($fileToUpload,$target_name="nahodne", $target_dir = "up/")
{
$imageFileType = strtolower(pathinfo($_FILES[$fileToUpload]["name"],PATHINFO_EXTENSION));
if ($target_name=="nahodne") $target_name=rand(100,99999);
$obrazek_plne_jmeno=$target_name .".". $imageFileType;
$target_file = $target_dir . $obrazek_plne_jmeno;
echo "
target file = ".$target_file."
";
$uploadOk = 1;
// if (file_exists($target_file)) { echo "Obrazek ".$target_file." uz existuje .";$uploadOk = 0; }
// Check file size
// 500 kb
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Moc velky soubor, max 500kb.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" && $imageFileType != "pdf") {
echo "Povoleno pouze JPG, JPEG, PNG & GIF, PDF.";
$uploadOk = 0;
}
if ($uploadOk == 1)
{
if (move_uploaded_file($_FILES[$fileToUpload]["tmp_name"], $target_file)) {
return true;
echo "
soubor ". $obrazek_plne_jmeno . " nahran ";
} else {
return false;
echo "
soubor ". $obrazek_plne_jmeno . " NEnahran ";
}}
else return false;
}
////////////////// KONEC FUNKCE NAHREJ_OBR //////////////////////
?>
11.11.2019 23:56:10