|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Renaming Of a File that Has Uploaded.
Hi,
In this module I have a user who logs in using his/her username and password. He/She is selecting a category, is able to upload files(html,gif,jpg) according to the category,A folder should create. and the folder name should be renamed to the file name that he is uploaded. and that file should be saved in the same folder. How do I go about it. As I'm able to create the folders and upload the files in the respective folders, but not able to rename the folder. Enclosing is the code that I'm using for creating the folders and uploading the files. <? session_start(); @ $username=$HTTP_SESSION_VARS['sess_user']; @ $category=$HTTP_POST_VARS['category']; @ $userfile=$HTTP_POST_FILES['userfile']; $dirname='./' .$username; $dirname1=$dirname. "/" . $category; $dirname2="./" . $username . "/" . $category ."/" . "images"; $destination="./" . $username ."/" . $category ."/" . "images"; $path_to_file=$dirname1; $flag=0; if (@ mkdir($dirname,0777)) { echo("successfully created Folder<br>"); } else { $flag=1; } if (@ mkdir($dirname1,0777)) { f echo("Successfully created the Folder<br>"); } else { //exit if; $flag=1; } $dir=opendir($path_to_file); while($file=readdir($dir)) { if (!ereg("/$", $path_to_file)) $path_to_file = $path_to_file."/"; foreach ($userfile['name'] as $key=>$name) { if ($userfile['size'][$key]) { // clean up file name $name = ereg_replace("[^a-z0-9._]", "", str_replace(" ", "_", str_replace("%20", "_", strtolower($name) ) ) ); $location = $path_to_file .$name; while (file_exists($location)) $location .= ".copy"; @ copy($userfile['tmp_name'][$key],$location); @ unlink($userfile['tmp_name'][$key]); } } } echo "\n Successfully uploaded file: $name."; ?> Regards, Renjith |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Renaming Of a File that Has Uploaded. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|