/** * @param Request $request * @return Attachment */ protected function addFileAttachment(Request $request) { $attachment = new Attachment(); $imageName = $request->file('uploaded-image')->getClientOriginalName(); $imageName = cleanFilename($imageName); $request->file('uploaded-image')->move(public_path() . '/uploads/', $imageName); $attachment->link = url() . '/uploads/' . $imageName; $attachment->type = 'image'; return $attachment; }
/** * load * * Takes a $_FILES object and sets the photo, filename and extension * variables. Then does some validation. * * @param FILES $photo * * @return UploadPhoto */ public function load($photo) { $this->photo = $photo; $this->fileName = cleanFilename($this->photo['name']); $this->setExtension(); $this->validate(); if ($this->fcmsError->hasUserError()) { return $this; } return $this; }
function iterateDirectory($dir) { foreach (glob($dir, GLOB_MARK) as $f) { if (is_dir($f)) { // If directory then skip for now } elseif (is_file($f)) { list($link, $title) = cleanFilename($f); echo "<li><a href=\"{$link}\">{$title}</a></li>" . PHP_EOL; } } }
/** * upload * * @param array $img * * @return boolean */ function upload($img) { if (empty($this->name)) { $this->name = cleanFilename($img['name']); } $this->type = $img['type']; // Get extension of photo $this->getExtension(); if (!$this->isValid()) { $this->error = 1; return false; } // Unique Filename if ($this->uniqueName) { $id = uniqid(""); $this->name = $id . '.' . $this->extension; } copy($img['tmp_name'], $this->destination . $this->name); return $this->name; }
/** * function output * * sends the generated PDF through the browser */ function output() { $filename = cleanFilename($this->settings["fileName"]); $this->reportOutput->Output($filename, "D"); }
$n_filename = ""; $trans = array("а" => "a", "б" => "b", "в" => "v", "г" => "g", "д" => "d", "е" => "e", "ё" => "yo", "ж" => "j", "з" => "z", "и" => "i", "й" => "i", "к" => "k", "л" => "l", "м" => "m", "н" => "n", "о" => "o", "п" => "p", "р" => "r", "с" => "s", "т" => "t", "у" => "u", "ф" => "f", "х" => "h", "ц" => "c", "ч" => "ch", "ш" => "sh", "щ" => "sh", "ы" => "i", "э" => "e", "ю" => "u", "я" => "ya", "А" => "A", "Б" => "B", "В" => "V", "Г" => "G", "Д" => "D", "Е" => "E", "Ё" => "Yo", "Ж" => "J", "З" => "Z", "И" => "I", "Й" => "I", "К" => "K", "Л" => "L", "М" => "M", "Н" => "N", "О" => "O", "П" => "P", "Р" => "R", "С" => "S", "Т" => "T", "У" => "U", "Ф" => "F", "Х" => "H", "Ц" => "C", "Ч" => "Ch", "Ш" => "Sh", "Щ" => "Sh", "Ы" => "I", "Э" => "E", "Ю" => "U", "Я" => "Ya", "ь" => "", "Ь" => "", "ъ" => "", "Ъ" => ""); $tmp_filename = strtr($filename, $trans); $filename = strtolower($tmp_filename); //Check that it only contains valid characters for ($i = 0; $i < strlen($filename); $i++) { if (in_array(substr($filename, $i, 1), $good_letters)) { $n_filename .= substr($filename, $i, 1); } } //If it got this far all is ok return $n_filename; } $uploaddir = '../../../../../userfiles'; $file_Name = $_FILES['upload']["name"]; $file_Name = cleanFilename($file_Name); $file_TmpName = $_FILES['upload']["tmp_name"]; $uploadfile = $uploaddir . '/' . $file_Name; $full_path = '/userfiles/' . $file_Name; $k = 0; while (is_file($uploadfile)) { $k++; $ext = pathinfo($file_Name, PATHINFO_EXTENSION); $uploadfile = $uploaddir . '/' . substr($file_Name, 0, strlen($file_Name) - strlen($ext) - 1) . '(' . $k . ').' . $ext; //$file_Name = substr($file_Name, 0, strlen($file_Name)-strlen($ext)-1).'('.$k.').'.$ext; $full_path = '/userfiles/' . substr($file_Name, 0, strlen($file_Name) - strlen($ext) - 1) . '(' . $k . ').' . $ext; } move_uploaded_file($file_TmpName, $uploadfile); $callback = $_REQUEST['CKEditorFuncNum']; //$full_path = '/userfiles/'.$file_Name; echo '<script type="text/javascript">window.parent.CKEDITOR.tools.callFunction("' . $callback . '", "' . $full_path . '","Файл загружен" );</script>';
#!/usr/bin/php -q <?php require_once dirname(dirname(__FILE__)) . '/test/lib/utils.php'; require_once TEST . 'lib/Test-More.php'; require_once INC . 'config_inc.php'; require_once INC . 'utils.php'; diag('cleanFilename'); plan(2); $spaces_in = 'New Microsoft Office Word Document.docx'; $spaces_out = cleanFilename($spaces_in); is($spaces_out, 'New_Microsoft_Office_Word_Document.docx', 'spaces'); $special_chr_in = 'test@#$%^&*()- 2314.zip'; $special_chr_out = cleanFilename($special_chr_in); is($special_chr_out, 'test-_2314.zip', 'special characters');
function output($to = "screen") { $filename = 'Client_Statement_' . date('Ymd') . '.pdf'; $filename = cleanFilename($filename); $this->pdf->output($filename, 'D'); }
/** * displayAddDocumentSubmit * * @return void */ function displayAddDocumentSubmit() { $doc = $_FILES['doc']['name']; $doc = cleanFilename($doc); $desc = $_POST['desc']; $mime = $_FILES['doc']['type']; $result = $this->fcmsDocument->uploadDocument($_FILES['doc'], $doc); if ($result === false) { $this->displayHeader(); $this->fcmsError->displayError(); $this->displayFooter(); return; } $sql = "INSERT INTO `fcms_documents` (\n `name`, `description`, `mime`, `user`, `date`\n ) VALUES(\n ?, ?, ?, ?, NOW()\n )"; $params = array($doc, $desc, $mime, $this->fcmsUser->id); if (!$this->fcmsDatabase->insert($sql, $params)) { $this->displayHeader(); $this->fcmsError->displayError(); $this->displayFooter(); return; } // Email members $sql = "SELECT u.`email`, s.`user` \n FROM `fcms_user_settings` AS s, `fcms_users` AS u \n WHERE `email_updates` = '1'\n AND u.`id` = s.`user`"; $rows = $this->fcmsDatabase->getRows($sql); if (count($rows) > 0) { $name = getUserDisplayName($this->fcmsUser->id); $url = getDomainAndDir(); $subject = sprintf(T_('%s has added a new document (%s).'), $name, $doc); $email_headers = getEmailHeaders(); foreach ($rows as $r) { $to = getUserDisplayName($r['user']); $email = $r['email']; $msg = T_('Dear') . ' ' . $to . ', ' . $subject . ' ' . $url . 'documents.php ---- ' . T_('To stop receiving these notifications, visit the following url and change your \'Email Update\' setting to No:') . ' ' . $url . 'settings.php '; mail($email, $subject, $msg, $email_headers); } } $_SESSION['ok'] = 1; header("Location: documents.php"); }
function output($destination = "screen", $userinfo = NULL) { switch ($destination) { case "screen": $userinfo = cleanFilename((string) $userinfo); $this->pdf->Output($userinfo, 'D'); break; case "email": if (!$userinfo) { $userinfo = $_SESSION["userinfo"]; } if (!$userinfo["email"] || !$this->invoicerecord["email"]) { return false; } $to = $this->invoicerecord["email"]; $toName = $this->invoicerecord["firstname"] . " " . $this->invoicerecord["lastname"]; $from = $userinfo["email"]; $fromName = $userinfo["firstname"] . " " . $userinfo["lastname"]; $subject = "Your " . $this->settings["reportTitle"] . " (" . $this->invoicerecord["id"] . ") from " . COMPANY_NAME; $pdf = $this->pdf->Output(NULL, "S"); $filename = $this->settings["reportTitle"] . "_" . $this->invoicerecord["id"] . ".pdf"; $mailer = $userinfo["mailer"]; $sendmail = $userinfo["sendmail"]; $smtpauth = $userinfo["smtpauth"]; $smtpsecure = $userinfo["smtpsecure"]; $smtpport = $userinfo["smtpport"]; $smtpuser = $userinfo["smtpuser"]; $smtppass = $userinfo["smtppass"]; $smtphost = $userinfo["smtphost"]; $messageTXT = 'Dear Client,\\n\\n' . 'Attached is your ' . $this->settings["reportTitle"] . ' from ' . COMPANY_NAME . '\\n\\n' . 'The attachment requires Adobe Acrobat Reader to view.\\n' . 'If you do not have Acrobat Reader, you can download it from http://www.adobe.com\\n\\n' . 'Kind Regards,\\n' . COMPANY_NAME; $messageHTML = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' . '<html>' . ' <head>' . ' <title>' . $subject . '</title>' . ' <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' . ' </head>' . ' <body>' . ' <p>' . ' Dear Client,</br>' . ' </br>' . ' Attached is your ' . $this->settings["reportTitle"] . ' from ' . COMPANY_NAME . '</br>' . ' </br>' . ' The attachment requires Adobe Acrobat Reader to view.</br>' . ' If you do not have Acrobat Reader, you can download it from <a href="http://www.adobe.com">Adobe</a></br>' . ' </br>' . ' Kind Regards,</br>' . ' ' . COMPANY_NAME . '</br>' . ' </p>' . ' </body>' . '</html>'; // Catch Exceptions try { require_once "swift-mailer/lib/swift_required.php"; // Create the Transport if ($mailer == "sendmail") { $transport = Swift_SendmailTransport::newInstance($sendmail); // Sendmail } elseif ($mailer == "smtp") { $transport = Swift_SmtpTransport::newInstance(); // SMTP $transport->setHost($smtphost); $transport->setPort($smtpport); if ($smtpauth) { $transport->setUsername($smtpuser); $transport->setPassword($smtppass); } if ($smtpsecure != "none") { $transport->setEncryption($smtpsecure); } } else { $transport = Swift_MailTransport::newInstance(); // Mail } // Create the Mailer using your created Transport $mailer = Swift_Mailer::newInstance($transport); // Create the message $message = Swift_Message::newInstance(); $message->setSubject($subject); // Give the message a subject $message->setFrom(array($from => $fromName)); // Set the From address with an associative array $message->setTo(array($to => $toName)); // Set the To addresses with an associative array $message->setBody($messageHTML, 'text/html'); // Give it a body $message->addPart($messageTXT, 'text/plain'); // And optionally an alternative body // Create the attachment with the pdf data $attachment = Swift_Attachment::newInstance($pdf, $filename, 'application/pdf'); $message->attach($attachment); // Attach it to the message // Send the message $result = $mailer->send($message); // Handle Exceptions } catch (Exception $ex) { echo '<label style="padding:4px 6px 4px 6px;"><b>Exception captured for (<u>' . $this->invoicerecord["id"] . '</u>) : </b>' . $ex->getMessage() . '</label></br>'; $result = FALSE; } return $result; break; } //endswitch }
/** * get Thumbnail for a movie * * @param string URL * @return string the URL to the cached image if exists or a link to img.php */ function getThumbnail($imgurl, $name = '') { // cover url not set? try local path instead if (!$imgurl && $name) { // be careful with the filename here- so clean it $localname = CACHE . '/' . CACHE_LOCAL . '/' . cleanFilename($name) . '.jpg'; // Small performance fix // if (file_exists($localname) && filesize($localname)) return($localname); if (@filesize($localname) > 0) { return $localname; } } // really an image? if (preg_match('/\\.(jpe?g|gif|png)$/i', $imgurl, $matches)) { // local file? - keep it! if (!preg_match('/^http/i', $imgurl)) { return $imgurl; } // file in cache? if (cache_file_exists($imgurl, $cache_file, CACHE_IMG, $matches[1])) { // double-check this is really an image if (@exif_imagetype($cache_file)) { return $cache_file; } } else { // add cache_ignore=1& to suppress additional cache lookup in img.php return 'img.php?url=' . urlencode($imgurl); } } // no image url given -> nopic return img(); }
function test_it_removes_special_characters() { $filename = 'Skärmavbild 2016-01-04 kl. 19.10.24.jpg'; $cleanFilename = cleanFilename($filename); $this->assertEquals('skrmavbild-2016-01-04-kl.-19.10.24.jpg', $cleanFilename); }
function output($destination = "screen", $userinfo = NULL) { switch ($destination) { case "screen": $userinfo = cleanFilename((string) $userinfo); $this->pdf->Output($userinfo, 'D'); break; case "email": if (!$userinfo) { $userinfo = $_SESSION["userinfo"]; } if (!$userinfo["email"] || !$this->receiptrecord["email"]) { return false; } $pdf = $this->pdf->Output(NULL, "S"); $to = $this->receiptrecord["email"]; $from = $userinfo["email"]; $subject = "Your " . $this->settings["reportTitle"] . " from " . COMPANY_NAME; $message = "Attached is your " . $this->settings["reportTitle"] . " from " . COMPANY_NAME . "\n\n" . "The attachment requires Adobe Acrobat Reader to view. \n If you do not " . "have Acrobat Reader, you can download it at http://www.adobe.com \n\n" . COMPANY_NAME . "\n" . COMPANY_ADDRESS . "\n" . COMPANY_CSZ . "\n" . COMPANY_PHONE; $headers = "From: {$from}"; $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; $pdf = chunk_split(base64_encode($pdf)); $message .= "--{$mime_boundary}\n" . "Content-Type: {application/pdf};\n" . " name=\"" . $this->settings["reportTitle"] . $this->receiptrecord["id"] . "\"\n" . "Content-Disposition: attachment;\n" . " filename=\"" . $this->settings["reportTitle"] . $this->receiptrecord["id"] . ".pdf\"\n" . "Content-Transfer-Encoding: base64\n\n" . $pdf . "\n\n" . "--{$mime_boundary}--\n"; return @mail($to, $subject, $message, $headers); break; } //endswitch }