File feltöltő nerandom nevet adjon
Sziasztok
Egész nap a neten keresgéltem egyszerű, átlátható filefeltöltőt, és egy olyat találtam amit énis használni tudok, és elég jó.
Az a baj hogy ez meg random névvel menti a feltöltött filet.
Tudna valaki segíteni, hogy mit töröljek, vagy írjak át hogy az eredeti file név maradjon?
■ Egész nap a neten keresgéltem egyszerű, átlátható filefeltöltőt, és egy olyat találtam amit énis használni tudok, és elég jó.
Az a baj hogy ez meg random névvel menti a feltöltött filet.
Tudna valaki segíteni, hogy mit töröljek, vagy írjak át hogy az eredeti file név maradjon?
- <?php
- ///////////////////////////////////////////////////////////////////////////////////////
- // PHPUpload //
- ///////////////////////////////////////////////////////////////////////////////////////
- // License: You are not to sell or distribute this software without permission //
- // Main Author: Brian //
- // Copyright reserved //
- ///////////////////////////////////////////////////////////////////////////////////////
- //////////////////////////////
- //Quick File Uplaod Class File
- //////////////////////////////
- class Upload{
- //set these values
- //////////////////
- var $uploadpassword = 'Jelszó a feltöltéshez'; //for you added security againt bots
- var $storage_folder = './files';
- var $site_url = './files'; //must be same as item above
- var $filesize_limit = 104857600; //= 100MB in bytes
- var $allowed_extensions = array('gif',
- 'jpg',
- 'bmp',
- 'png',
- 'jpeg'); //this checks the files extension but is not enough security on its own, hence the next section below
- var $allowed_file_types = array('image/gif',
- 'image/jpg',
- 'image/jpeg',
- 'image/pjpeg',
- 'image/x-png',
- 'image/bmp',
- 'image/png',
- 'application/x-gzip',
- 'multipart/x-gzip',
- 'application/x-compressed',
- 'application/x-zip-compressed',
- 'application/zip',
- 'multipart/x-zip',
- 'application/x-tar',
- 'application/gnutar',
- 'application/pdf',
- 'video/mpeg',
- 'application/octet-stream'); //checks files MIME type for added security
- ///////////////////////////////////////////DO NOT EDIT BELOW THIS LINE /////////////////////////////////
- //uplaoded file info
- var $filename;
- var $file_content;
- var $filesize_actual;
- var $filetype_actual;
- var $password;
- var $filelink;
- var $message;
- var $show_error;
- //initiate the uplaod class
- ///////////////////////////
- function Upload(){
- $this->password = htmlspecialchars($_POST['password']);
- $this->message = '';
- $this->filelink = '';
- $this->load_error ='';
- $this->show_error = false;
- //check if form has been submitted
- //////////////////////////////////
- if (!$_FILES){
- $this->showview();
- }else{
- //Form has been submitted
- $this->filename = $_FILES['myfile']['name'];
- $this->file_content = $_FILES['myfile']['tmp_name'];
- $this->filesize_actual = $_FILES['myfile']['size'];
- $this->filetype_actual = strtolower($_FILES['myfile']['type']);
- //check passowrd
- if ($this->password != $this->uploadpassword || $this->password ==''){
- $this->show_error = true;
- $this->message = 'Rosz a jelszavad!';
- $this->showview();
- }
- //check file has been selected for upload
- if ($this->filesize_actual <= 0){
- $this->show_error = true;
- $this->message = 'Filet válassz';
- $this->showview();
- }
- //check file size
- if ($this->filesize_actual > $this->filesize_limit){
- $this->show_error = true;
- $this->message = 'Nemjó, túl nagy a kép';
- $this->showview();
- }
- //check file type
- if (!in_array($this->filetype_actual, $this->allowed_file_types)){
- $this->show_error = true;
- $this->message = 'Csak képet tölthetsz fel';
- $this->showview();
- }
- //check file extension
- $file_extension = end(explode('.',$this->filename));
- if (!in_array($file_extension, $this->allowed_extensions) || $file_extension ==''){
- $this->show_error = true;
- $this->message = 'Csak képet tölthetsz fel';
- $this->showview();
- }
- //check if storage folder is writable
- if (!is_writeable($this->storage_folder)){
- $this->show_error = true;
- $this->message = 'A mappa most zárva van';
- $this->showview();
- }
- //finished, save file
- //////////////////////
- $filename_random_code = $this->randomcode();
- $filename_random = $this->storage_folder.'/'.$filename_random_code.'.'.$file_extension;
- if (!move_uploaded_file($_FILES['myfile']['tmp_name'], $filename_random)) {
- $this->show_error = true;
- $this->message = 'Nem jó valami, próbáld újra';
- $this->showview();
- }else{
- $this->filelink = $this->site_url.'/'.$filename_random_code.'.'.$file_extension;
- $this->show_error = true;
- $this->message = 'Késsz, ezen a linken ellenőrizheted.';
- $this->showview();
- }
- //end
- }
- }
- /////////////
- //Show page
- /////////////
- function showview(){
- if ($this->show_error==true){
- $load_error = '<div align="center"><center><table border="0" cellpadding="0" cellspacing="0" width="653">
- <tr><td bgcolor="#FFFFFF" colspan="2" width="611"> </td></tr></center><tr><td bgcolor="#FFFFFF" width="156">
- <p align="right"><b><font face="Arial" size="2"> <img border="0" src="icon.gif" width="25" height="25">
- </font></b></td><center><td bgcolor="#FFFFFF" width="493"><font face="Arial" size="2" color="#006699">'.$this->message.'</font>
- </td></tr></table></center></div>';
- }
- echo '
- <form action="index.php" method="post" enctype="multipart/form-data" ><div align="center"><center><table border="0" cellpadding="0" cellspacing="0" width="446" height="89" style="border: 1px solid #EBEBEB">
- <tr><td width="442" colspan="2" bgcolor="#EBEBEB" height="26"><p align="center"><b><font face="Arial" size="2"> Kép feltöltés </font></b></td>
- </tr><tr><td width="114" height="21" bgcolor="#FFFFFF"></td><td width="328" height="21" bgcolor="#FFFFFF"></td></tr></center><tr><td width="114" height="21" bgcolor="#FFFFFF">
- <p align="right"><font face="Arial" size="2">Jelszó </font></td><center><td width="328" height="21" bgcolor="#FFFFFF"><input type="password" name="password" size="20"></td>
- </tr></center><tr><td width="114" height="21" bgcolor="#FFFFFF"><p align="right"><font face="Arial" size="2">Kép </font></td>
- <td width="328" height="21" bgcolor="#FFFFFF"><input name="myfile" type="file" size="30" /></td></tr><tr><td width="114" height="21" bgcolor="#FFFFFF"></td>
- <td width="328" height="21" bgcolor="#FFFFFF"></td></tr><tr><td width="114" height="21" bgcolor="#FFFFFF"> </td><td width="328" height="21" bgcolor="#FFFFFF"><input type="submit" value="Mehet" name="B1"></td>
- </tr><tr><td width="114" height="21" bgcolor="#FFFFFF"><p align="right"></td><center><td width="328" height="21" bgcolor="#FFFFFF"> </td></tr>
- </table></center></div><!-- error table -->'.$load_error.'<!-- error table end --><!-- link table --><div align="center"><center><table border="0" cellpadding="0" cellspacing="0" width="653" height="40">
- <tr><td height="22"></td></tr><tr><td height="18"><p align="center"><a href="'.$this->filelink.'" target="_blank"><font face="Arial" size="4">'.$this->filelink.'</font></a></td>
- </tr></table></center></div><!-- link table end --><p align="center"> </p></form>';
- die();
- }
- //////////////////
- //random code
- //////////////////
- function randomcode() {
- $chars = "abcdefghijkmnopqrstuvwxyz023456789";
- srand((double)microtime() * 1000000);
- $i = 0;
- $pass = '';
- while ($i <= 15) {
- $num = rand() % 33;
- $tmp = substr($chars,$num,1);
- $pass = $pass.$tmp;
- $i++;
- }
- return $pass;
- }
- }
- ?>
random_code
UPDATE:
így nézne ki változatlan névvel:
Nem működik
persze..
(És a könnyebb átláthatóság miatt használd a "Válasz" linket, hogy a kapcsolódó üzenet váltások jól látszódjanak.)
Sikerült
Köszönöm
Ácsi
Huhh...
Hmmm. Itt volt még egy hozzászólása Meli-nek az ajánlott 12-es pontra vonatkozóan, azzal vajon mi lett?... http://weblabor.hu/forumok/temak/106526
.
de nagyon jó ha elolvastad, mert neked írtam TeeCee...
Ha nekem...
Részemről nincs harag, csak egyszerűen nem dolgoztam helyetted és ezt - úgy érzem - zokon vetted. Pont azért linkeltem be a "Hogyan kérdezz" cikket, mert rendszeresen jönnek akik kész kódot/megoldást szeretnének kapni = másokat szeretnének dolgoztatni.
Mindenesetre befejeztem az OFF-olást, ha továbbiakban erről szeretnél értekezni, azt privát elérhetőségeimen tedd.
Üdv:
TeeCee :o)