PageRenderTime 38ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/public/js/redactor/image_upload.php

https://github.com/lslucas/105fm
PHP | 35 lines | 18 code | 11 blank | 6 comment | 10 complexity | 7e16b7971926ba3372b751b4a595df56 MD5 | raw file
  1. <?php
  2. // This is a simplified example, which doesn't cover security of uploaded images.
  3. // This example just demonstrate the logic behind the process.
  4. // files storage folder
  5. $dir = "../../files/";
  6. $_FILES['file']['type'] = strtolower($_FILES['file']['type']);
  7. if ($_FILES['file']['type'] == 'image/png'
  8. || $_FILES['file']['type'] == 'image/jpg'
  9. || $_FILES['file']['type'] == 'image/gif'
  10. || $_FILES['file']['type'] == 'image/jpeg'
  11. || $_FILES['file']['type'] == 'image/pjpeg')
  12. {
  13. // setting file's mysterious name
  14. $file = $dir.md5(date('YmdHis')).'.jpg';
  15. // copying
  16. copy($_FILES['file']['tmp_name'], $file);
  17. $file = "/files/".md5(date('YmdHis')).'.jpg';
  18. // displaying file
  19. $array = array(
  20. 'filelink' => $file
  21. );
  22. echo stripslashes(json_encode($array));
  23. }
  24. ?>