phpnoob123 Posted December 29, 2010 Share Posted December 29, 2010 Ok so for my code, i need to create a new folder on my cpanel server by user input (html form)... The folder is created, then I want the user to click a button which will have two functions... one to copy a ZIP file to that (user generated) folder... and two... EXTRACT that ZIP file in the folder. Here is my code... it has no errors... the folder is being created by the user input, but the ZIP file is not copied into it, and is obviously not being extracted... PS... please don't laugh at my code.. im only coding for a few short months. <?php //Get folder name from form string $_SERVER['QUERY_STRING']; $folderName = $_POST['folderName']; //Path to where you want to create the new folder $path = "folders/"; //Complete path to new folder $d = $path . $folderName; mkdir($d, 0755); echo "Folder " . $d . " has been created."; echo '<br />_________________________________________________________________<br /><br />'; echo "Lets get started... click next to continue"; if(isset($_POST['submit'])) { copy_zip_file(); extract_zip_file(); } function copy_zip_file(){ $old = 'test.zip'; $new = '/folders/$folderName/test.zip'; copy($old, $new) or die("Unable to copy $old to $new."); } function extract_zip_file(){ $zip = new ZipArchive; $res = $zip->open(’folders/$folderName/test.zip’); if ($res === TRUE) { $zip->extractTo(’folders/$folderName/’); $zip->close(); echo ‘ok’; } else { echo ‘failed’; } } ?> <form action="nav.php" name="submit" method="post"> <input class="button" type="submit" value="Submit"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/222856-noob-needs-help-no-errors-but-code-not-functioning/ Share on other sites More sharing options...
JD* Posted December 29, 2010 Share Posted December 29, 2010 Try doing the copy with exec instead (assuming you're on a unix hosting system, cp) and see if that works. If so, your host may have disabled the copy command http://php.net/manual/en/function.exec.php Quote Link to comment https://forums.phpfreaks.com/topic/222856-noob-needs-help-no-errors-but-code-not-functioning/#findComment-1152420 Share on other sites More sharing options...
phpnoob123 Posted December 29, 2010 Author Share Posted December 29, 2010 Thanks.. unfortunately a little beyond my knowledge.. I'll try to google that. Thanks for pointing me in the right direction, much appreciated!! ps.. any other help will be MUCH appreciated! =) Quote Link to comment https://forums.phpfreaks.com/topic/222856-noob-needs-help-no-errors-but-code-not-functioning/#findComment-1152428 Share on other sites More sharing options...
JD* Posted December 29, 2010 Share Posted December 29, 2010 Ok, so replace this: if(isset($_POST['submit'])) { copy_zip_file(); extract_zip_file(); } function copy_zip_file(){ $old = 'test.zip'; $new = '/folders/$folderName/test.zip'; copy($old, $new) or die("Unable to copy $old to $new."); } with this if(isset($_POST['submit'])) { if(exec("cp ".$old." ".$new)) { extract_zip_file(); } else { die("Unable to copy $old to $new"); } } See if that works. Quote Link to comment https://forums.phpfreaks.com/topic/222856-noob-needs-help-no-errors-but-code-not-functioning/#findComment-1152547 Share on other sites More sharing options...
DavidAM Posted December 29, 2010 Share Posted December 29, 2010 I really think your problem is here (in copy_zip_file()): // THIS $new = '/folders/$folderName/test.zip'; //SHOULD BE THIS $new = "folders/$folderName/test.zip"; That is not the same path where you just created the folder. The slash "/" at the beginning of the path indicates the root of the server's filesystem, I seriously doubt that that is the path to your folders directory. Remove that first slash and use double-quotes and you should be golden. Also, you are using "smart quotes" (which I don't think are really that smart ...) in the extract_zip_file() function. See the ones that are leaning to the right or left? They need to be single quotes or double-quotes like they are in the rest of your code. (The ones with variable names in them, need to be double-quotes): function extract_zip_file(){ $zip = new ZipArchive; $res = $zip->open("folders/$folderName/test.zip"); // This line if ($res === TRUE) { $zip->extractTo("folders/$folderName/"); // This line $zip->close(); echo 'ok'; // This line } else { echo 'failed'; // This line } } Quote Link to comment https://forums.phpfreaks.com/topic/222856-noob-needs-help-no-errors-but-code-not-functioning/#findComment-1152568 Share on other sites More sharing options...
phpnoob123 Posted December 29, 2010 Author Share Posted December 29, 2010 Thank guys... Just tryed both solutions... but no luck =/ This is frustrating.. such a simple task (i thought) The problem lies with the copying of the file.. its just not duplicating the file at all.. It makes the folder correctly (with user input as the foldername) But no copy of the ZIP file? stumped.. Quote Link to comment https://forums.phpfreaks.com/topic/222856-noob-needs-help-no-errors-but-code-not-functioning/#findComment-1152593 Share on other sites More sharing options...
DavidAM Posted December 29, 2010 Share Posted December 29, 2010 Are you sure the zip file is in the directory with the script? Turn on error reporting. (Add these two lines immediately after your openning PHP tag: error_reporting(E_ALL); ini_set('display_errors', 1); Post any messages you receive along with your current code. Quote Link to comment https://forums.phpfreaks.com/topic/222856-noob-needs-help-no-errors-but-code-not-functioning/#findComment-1152596 Share on other sites More sharing options...
phpnoob123 Posted December 29, 2010 Author Share Posted December 29, 2010 Error reporting on.. I see no errors.. I tryed both suggestions.. but here is the code I have now; <?php error_reporting(E_ALL); ini_set('display_errors', 1); //Get folder name from form string $_SERVER['QUERY_STRING']; $folderName = $_POST['folderName']; $path = "folders/"; //Complete path to new folder $d = $path . $folderName; mkdir($d, 0755); echo "Folder " . $d . " has been created."; echo '<br />_________________________________________________________________<br /><br />'; echo "Lets get started... click next to continue"; if(isset($_POST['submit'])) { copy_zip_file(); extract_zip_file(); } function copy_zip_file(){ $old = "test.zip"; $new = "folders/$folderName/test.zip"; copy($old, $new) or die("Unable to copy $old to $new."); } function extract_zip_file(){ $zip = new ZipArchive; $res = $zip->open(’folders/$folderName/test.zip’); if ($res === TRUE) { $zip->extractTo(’folders/$folderName/’); $zip->close(); echo ‘ok’; } else { echo ‘failed’; } } ?> <form action="nav.php" name="submit" method="post"> <input class="button" type="submit" value="Submit"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/222856-noob-needs-help-no-errors-but-code-not-functioning/#findComment-1152602 Share on other sites More sharing options...
phpnoob123 Posted December 29, 2010 Author Share Posted December 29, 2010 PS... i do have the ZIP file in the directory Quote Link to comment https://forums.phpfreaks.com/topic/222856-noob-needs-help-no-errors-but-code-not-functioning/#findComment-1152603 Share on other sites More sharing options...
phpnoob123 Posted December 29, 2010 Author Share Posted December 29, 2010 STOP THE PRESSES... just contacted my hosting co.. copy() and shell not allowed.. =( Thanks guys.. good to know that help is available! very much appreciated and happy new year. Quote Link to comment https://forums.phpfreaks.com/topic/222856-noob-needs-help-no-errors-but-code-not-functioning/#findComment-1152607 Share on other sites More sharing options...
Maq Posted December 29, 2010 Share Posted December 29, 2010 STOP THE PRESSES... just contacted my hosting co.. copy() and shell not allowed.. =( Thanks guys.. good to know that help is available! very much appreciated and happy new year. Who are you hosted with? Quote Link to comment https://forums.phpfreaks.com/topic/222856-noob-needs-help-no-errors-but-code-not-functioning/#findComment-1152622 Share on other sites More sharing options...
phpnoob123 Posted December 29, 2010 Author Share Posted December 29, 2010 HGator... I just switched hosting co's and tryed the code without success.... code is not even giving errors where I can see where the problem is.. frustrating. The zip file is just not copying into the folder. Quote Link to comment https://forums.phpfreaks.com/topic/222856-noob-needs-help-no-errors-but-code-not-functioning/#findComment-1152623 Share on other sites More sharing options...
mattal999 Posted December 29, 2010 Share Posted December 29, 2010 I think the problem may be here. Correct me if I'm wrong, but to write to that folder via PHP you would need to chmod the folder to 0777? Try changing: mkdir($d, 0755); To: mkdir($d, 0777); Quote Link to comment https://forums.phpfreaks.com/topic/222856-noob-needs-help-no-errors-but-code-not-functioning/#findComment-1152629 Share on other sites More sharing options...
PFMaBiSmAd Posted December 29, 2010 Share Posted December 29, 2010 Your form does not have a field named submit, so your code is never being executed because if(isset($_POST['submit'])) { will never be TRUE. Fix your form so that it actually contains a form field with name='submit' Quote Link to comment https://forums.phpfreaks.com/topic/222856-noob-needs-help-no-errors-but-code-not-functioning/#findComment-1152635 Share on other sites More sharing options...
phpnoob123 Posted December 29, 2010 Author Share Posted December 29, 2010 PFM.. on the bottom of the code.. the form does have a "name="submit" ... not sure where to edit? Quote Link to comment https://forums.phpfreaks.com/topic/222856-noob-needs-help-no-errors-but-code-not-functioning/#findComment-1152639 Share on other sites More sharing options...
PFMaBiSmAd Posted December 29, 2010 Share Posted December 29, 2010 That's in the <form> tag. All the does is give your form a name. <input class="button" type="submit" name="submit" value="Submit"> Quote Link to comment https://forums.phpfreaks.com/topic/222856-noob-needs-help-no-errors-but-code-not-functioning/#findComment-1152640 Share on other sites More sharing options...
phpnoob123 Posted December 29, 2010 Author Share Posted December 29, 2010 Got it working!! you we're right about the form... added: <input type="text" name="folderName" value="" /> Thanks a MILLION! Quote Link to comment https://forums.phpfreaks.com/topic/222856-noob-needs-help-no-errors-but-code-not-functioning/#findComment-1152653 Share on other sites More sharing options...
grilo Posted January 25, 2011 Share Posted January 25, 2011 Dear sirs... I´m sorry for asking but can you assist me? This php script is exactly what i was looking for, but it dosen´t work for me rather then creating a file "folders" Here´s error report: "Notice: Undefined index: folderName in /hsphere/local/home/gdr2010/webrestaurante.info/teste/teste/teste4.php on line 7 Folder folders/ has been created." How can i define the index folder? Thanks for the reply and sorry for the trouble. Quote Link to comment https://forums.phpfreaks.com/topic/222856-noob-needs-help-no-errors-but-code-not-functioning/#findComment-1164935 Share on other sites More sharing options...
Maq Posted January 25, 2011 Share Posted January 25, 2011 Dear sirs... I´m sorry for asking but can you assist me? This php script is exactly what i was looking for, but it dosen´t work for me rather then creating a file "folders" Here´s error report: "Notice: Undefined index: folderName in /hsphere/local/home/gdr2010/webrestaurante.info/teste/teste/teste4.php on line 7 Folder folders/ has been created." How can i define the index folder? Thanks for the reply and sorry for the trouble. Please start a new thread for your issue. Quote Link to comment https://forums.phpfreaks.com/topic/222856-noob-needs-help-no-errors-but-code-not-functioning/#findComment-1165025 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.