ksamir2004 Posted April 11, 2008 Share Posted April 11, 2008 I am posting code to you... please help us.. my Question is: while uploading file i need to remove spaces & special character like *, -,/ etc. example: sam file.xls Ans should be: samfile.xls So i am pasting code: ----------------------------------------- -------------------------------------------- File name is : upload_rename.php ----------------------------------------------- <html><head>name this file</head> <body> <table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form action="upload_rename.php " method="post" enctype="multipart/form-data" name="form1" id="form1"> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td><strong>Single File Upload </strong></td> </tr> <tr> <td>Select file <input name="ufile" type="file" id="ufile" size="50" /></td> </tr> <tr> <td align="center"><input type="submit" name="Submit" value="Upload" /></td> </tr> </table> </td> </form> </tr> </table> <?php $file_name=$HTTP_POST_FILES['ufile']['name']; $file_ext1 = explode(".", $file_name); $file_ext = count($file_ext1); $file_ext = strtolower($file_ext1[$file_ext-1]); $special = array('/','!','&','*',' ','-'); //$new_file_name = str_replace(' ',' ',str_replace($special,'',$file_name)); /* for random name, use this: $random1 = "123456789012345678901234567890123456789012345678901234567890"; $random2 = "abcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVWXYZYZ"; $random2 .= "abcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVWXYZYZ"; $name = trim(substr(str_shuffle($random1.$random2),1,3).substr(str_shuffle($random1.$random2),1,3)); $new_file_name = $name.".".$file_ext;*/ $new_file_name= "newname".".".$file_ext; echo '['.$new_file_name.']';$path= "uploads/File/".$new_file_name; if($ufile !=none) {if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path)) {echo "Successful<BR/>";echo "File Name :".$new_file_name."<BR/>"; echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>"; }else{echo "Error"; } } ?> </body> </html> Thanks in advance.. Please mail this code after correction.. Thanks Sam Link to comment https://forums.phpfreaks.com/topic/100618-how-to-change-file-name-while-uploading-in-php/ Share on other sites More sharing options...
MiCR0 Posted April 11, 2008 Share Posted April 11, 2008 http://php.about.com/od/advancedphp/ss/rename_upload_2.htm Link to comment https://forums.phpfreaks.com/topic/100618-how-to-change-file-name-while-uploading-in-php/#findComment-514580 Share on other sites More sharing options...
conker87 Posted April 11, 2008 Share Posted April 11, 2008 Well, you're not going to get files with '/', '*' in anyway, since they're illegal characters. Link to comment https://forums.phpfreaks.com/topic/100618-how-to-change-file-name-while-uploading-in-php/#findComment-514591 Share on other sites More sharing options...
ksamir2004 Posted April 11, 2008 Author Share Posted April 11, 2008 main thing is i need to remove blank space form file name Example: file x uploaded.xls Ans should be: filexuploaded.xls this code gived file extension <?php //This function separates the extension from the rest of the file name and returns it function findexts ($filename) { $filename = strtolower($filename) ; $exts = split("[/\\.]", $filename) ; $n = count($exts)-1; $exts = $exts[$n]; return $exts; } //This applies the function to our file $ext = findexts ($_FILES['uploaded']['name']) ; --------------------------------------------- i need complete solution .. plz help us... Thanks sam Link to comment https://forums.phpfreaks.com/topic/100618-how-to-change-file-name-while-uploading-in-php/#findComment-514605 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.