Hi, everyone......................I need this help please, I have a website which allow users to upload files, I want every username has his own folder, so that if there is no folder with the same name ....a folder with his name is created automatically and the file saved in the new formed folder...........I don't know how to do this and which code I use, however, this is the code I used to allow users upload files ///////beginning//////// <html> <body> <form action="Testing_upload.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </hr> <?php if($_FILES){ if($_FILES["file"]["error"]==0){ $filename = $_FILES["file"]["name"]; $temp = $_FILES["file"]["tmp_name"]; $size = $_FILES["file"]["size"]; $dest = "Upload/" .time() . "_" . $filename; $ext= pathinfo($filename, PATHINFO_EXTENSION); $allowed = array ("jpg","gif","png","jpeg"); if($size>1024*2000)echo"Size is too large, Maximum size is 2 MB"; elseif($size==0)echo"Size Cannot be ZERO (0), Please upload the correct file"; elseif(!in_array($ext,$allowed))echo"The type of file is not allowed"; else{ move_uploaded_file ($temp,$dest); echo"Your file is uploaded successfully"; } } else echo"Error of file uploading"; } ?> </body> </html> ////////////end/////// this code is working and files are saved in "upload", but inside "upload" I want each user to has his own folder and inside his own folder these files are saved.
if you want to create folder for each user basics, then you need to have login page, so that each user can have their own unique ID. Because through name we can't distinguish users, many people can have same name. Each user will login to website through their unique id and then upload the image. then you need to write the code to create a folder for each user id if it doesn't exist and save users file in that folder. $userid = "xyz"; if(file_exists ( $userid )) //check wether username folder exist or not { write file in this folder }else{ mkdir($userid);//create foder and copy files in this } Let me know if u need further help Sheetal
hi, i would like to share some points on creating a PHP file: PHP files can contain text, HTML tags and scripts PHP files are returned to the browser as plain HTML PHP files have a file extension of ".php", ".php3", or ".phtml"
SheetalCreation, thanks for your help, however,:- 1- My website allow the user to login and logout 2- The username of each user I made it so that it could not be repeated. 3- so the name of the folder will depend on the Username 4-finally, Iwant to know where I have to put this code?
Great! You have all required code. To verify user is loged in or not you must be saving some cookie at client and maintaining some session. When user is clicking on submit/upload button, inorder to upload the file, in your case "Testing_upload.php" action is getting executed. in Testing_upload.php file first you need to varify whether user a valid loged in user or not. If user is a valid user then extract the user id from db( or from where ever you have saved). then check for userId named folder exists or not, say all folders you are saving under usersFile folder then check if(file_ exists("usersFile/usetId")) { //if folder exist then check for same file exist or not. $filename = $_FILES["file"]["name"]; if(file_ exists("usersFile/usetId/$filename")){ if same name file is already exist then you can simply save file exist and return }else{ save file using move_uploaded_file } }else{ file folder does not exist then create a folder and move uploaded file under that folder. } ?> Let me know if u need further help Sheetal