siamsam Posted June 22, 2010 Share Posted June 22, 2010 Hello all. I need a little help in a project I am working on. I am not sure if it is even possible to do what I am hoping for, or if it is a secure way to accomplish it. Here is what I would like to achieve: 1. sales rep enters info about order into a form & info goes into database (I have this part) 2. once the new record is created, I want the magic of PHP to create a new directory for the customer (i.e. named 'customer_name') 3. in the directory I want it to automatically include a copy of /forms/bizpagetemplate.php and two copies of /forms/coupontemp.jpeg - all three writable only with that customer's permissions (username and pass is set when rep enters in form) 4. then I want to have an email sent to the customer with the link to the file Is this possible? I am new to PHP and would appreciate any comments on how to achieve this. And if possible, tips on security measures when doing something like this. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/205557-creating-a-new-directory-with-files/ Share on other sites More sharing options...
radar Posted June 22, 2010 Share Posted June 22, 2010 This is quite possible actually... First off the magic of php, when talking about making a directory isnt that difficult... to do that you simply do this: <?php mkdir("/path/to/my/dir", 0700); ?> simple ey? copying isnt too much harder either. <?php $file = '/forms/bizpagetemplate.php'; $newfile = '/client/index.php'; if (!copy($file, $newfile)) { echo "failed to copy $file...\n"; } ?> as you can see in the first part, you are creating the directory and setting permissions at the same time. second part, you are copying a non-standard document root file (ie: index.php), and are copying it to your desired location but not before making it the initial loadup file. Hope it helps. Quote Link to comment https://forums.phpfreaks.com/topic/205557-creating-a-new-directory-with-files/#findComment-1075604 Share on other sites More sharing options...
mboley370 Posted June 22, 2010 Share Posted June 22, 2010 This can be done, but I would think this through a little. What happens if there is a second customer. You need to have a way to check to make sure that the directory that you want to create doesn't exist first. I found a quick example for you here http://www.daniweb.com/forums/thread115915.html This would have to be edited so that you can tell it to create a directory name $PersonsName = ['nameFieldEntered"] so mkdir($PersonsName) $uploaddir1 = "resumes/".$_SESSION["uss1"]."/".$uname; echo $uploaddir1; if(is_dir($uploaddir1)) { echo "Exists!"; } else { echo "Doesn't exist" ; mkdir($uploaddir1,0777); print "created"; } Whith that being said I would then do a check. Such as above check again if the file was created. If the file was created. Run a sql insert kind of like this. So that you can run a check to insert into your table you would have to do something like this $name = ['nameFieldEntered'] // The namefieldEntered is obviously going to be your directory name. $file1 = The file you want to insert $file2 = the file you want to insert if(is_dir($name)) { $query "insert $file1, $file2 into $name"; I hope this helps a little. Just let me know. Quote Link to comment https://forums.phpfreaks.com/topic/205557-creating-a-new-directory-with-files/#findComment-1075608 Share on other sites More sharing options...
siamsam Posted June 22, 2010 Author Share Posted June 22, 2010 Thank you both for your responses! I am going to try it out, I am still building the form so when I am done I will see if it works. Two more questions... Will I run into a problem with concurrent users if the script is trying to copying those files at the same time for two different customers? Since the rep will be the one initiating the script, this most likely won't happen but I figured I would ask. I suppose I am just not sure how PHP goes about copying a file - whether it just reads and copies or actually causes the file to be "busy" (if you will). Hope this makes sense. Also, what I am trying to do with one of the image templates that will be copied, is to have users fill in a form to add text and upload a logo. It then will insert it into the image as a new image. The problem I am having is that I need to also include links specific to the customer. To get an idea of what I am talking about check out this site: http://www.mingamo.com/mingamo/search.php?category_id=34 The links I am referring to are the ones at the bottom of the coupon. I looked at their code to get an idea and it looks like each coupon is returned within a table. Do we think that the tables were created within the html or directly from the PHP? That is the only way I could think of doing this. But again - I am a big PHP newbie! Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/205557-creating-a-new-directory-with-files/#findComment-1075849 Share on other sites More sharing options...
radar Posted July 12, 2010 Share Posted July 12, 2010 No, the script does instantiate in that way, so one client wont be interfering with another client (and by client i mean browser). Quote Link to comment https://forums.phpfreaks.com/topic/205557-creating-a-new-directory-with-files/#findComment-1085087 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.