123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- // Return a slug from the entered string
- function slugify($str) {
- $search = array('Ș', 'Ț', 'ş', 'ţ', 'Ş', 'Ţ', 'ș', 'ț', 'î', 'Î', 'ï', 'Ï', 'â', 'Â', 'à', 'À', 'ă', 'Ă', 'ë', 'Ë', 'ê', 'Ê', 'è', 'È', 'é', 'É', 'û', 'Û', 'ô', 'Ô');
- $replace = array('s', 't', 's', 't', 's', 't', 's', 't', 'i', 'i', 'i', 'i', 'a', 'a', 'a', 'a', 'a', 'a', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'u', 'u', 'o', 'o');
- $str = str_ireplace($search, $replace, strtolower(trim($str)));
- $str = preg_replace('/[^\w\d\-\ ]|^ +| +$/', '', $str);
- $str = str_replace(' ', '-', $str);
- return preg_replace('/\-{2,}/', '-', $str);
- }
- // Move the image to its final destination
- function uploadImage($file, $fileDestination = "./images/")
- {
- $fileName = $file['name'];
- $fileType = $file['type'];
- $fileTempName = $file['tmp_name'];
- $fileError = $file['error'];
- $fileSize = $file['size'];
- $fileExt = explode('.', $fileName);
- $fileActualExt = strtolower(end($fileExt));
- $allowedExts = array(
- 'jpg',
- 'jpeg',
- 'png',
- 'svg',
- 'gif'
- );
- if (in_array($fileActualExt, $allowedExts))
- {
- if ($fileError === 0)
- {
- if ($fileSize < 2000000)
- {
- $fileNewName = uniqid("", true) . "." . $fileActualExt;
- $fileDestination = $fileDestination . $fileNewName;
- move_uploaded_file($fileTempName, $fileDestination);
- return $fileNewName;
- }
- else
- {
- return false; // error: file size too big
- }
- }
- else
- {
- return false; // error: error uploading file
- }
- }
- else
- {
- return false; // error: file ext not allowed
- }
- }
- ?>
|