Fabis94 Posted April 5, 2009 Share Posted April 5, 2009 Here's the script: if (!isset($_POST['name_added_get']) && !isset($_POST['write_cont']) && !isset($_POST['second_method'])) { echo '<br><br><hr>You can also upload a page instead of making a new one. Select the file below, select its destination '; echo 'and press "Upload File"<br>'; echo "<form action='upload_file.php' method='post'"; echo "enctype='multipart/form-data'>"; echo "<label for='file'>Filename:</label>"; echo "<input type='file' name='file' id='file' />"; echo "<br /><input type='hidden' name='MAX_FILE_SIZE' value='30000' /><br><input name='upload_dir' type='text' value='/' />"; echo "<input type='submit' name='upload' value='Submit' />"; echo "</form>"; if (isset($_POST['upload'])) {//If Upload Button is Pressed $upload_dir = $_POST['upload_dir']; if ($_POST['upload_dir'] != '/') { if (substr($_POST['upload_dir'], -1) != '/' || substr($_POST['upload_dir'], 0, 1) != '/') { echo '<script language"text/javascript">alert("Folder Location must start and end with /");</script>'; echo '<script type="text/javascript">window.location="newpage.php";</script>'; exit; } }//Correct Folder IF Ends if (file_exists($def_path . $_POST['upload_dir'])) {//ABC: /home/content/f/a/b/fabis94/html $filepath = $def_path . $_POST['upload_dir'] . basename($_FILES["file"]["name"]); $filename = basename($_FILES["file"]["name"]); echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Stored in: " . $_FILES["file"]["tmp_name"]; echo 'Up dir: ' . $_POST['upload_dir'] . ' Original Basename: ' . $_FILES["file"]["name"] . 'Filepath: ' . $filepath . ' <br>'; if (!file_exists($filepath)) {//If PHPNAME doesn't and FOLDERLOCATION exists if (substr($filename, -4) == '.php') {//If it is a PHP file if (move_uploaded_file($_FILES["file"]["tmp_name"], $filepath)) { echo "<br><font color='green'>File is valid, and was successfully uploaded.</font>\n"; } else { echo "<br><font color='red'>Couldn't upload and move.</font>\n"; } } else { echo '<script language"text/javascript">alert("File must be .PHP");</script>'; echo '<script type="text/javascript">window.location="newpage.php";</script>'; } } else { echo '<script language"text/javascript">alert("Page already exists in the specified directory");</script>'; /*echo '<script type="text/javascript">window.location="newpage.php";</script>';*/ exit; }//PHPNAME Exists IF ends here } else { echo '<script language"text/javascript">alert("The directory you specified doesnt exist");</script>'; echo '<script type="text/javascript">window.location="newpage.php";</script>'; exit; }//FOLDERLOCATION Exists IF ends here }//Upload Button IF ends }//Upload method ends It just simpy says "Folder Location must start and end with /" in the pop-up window and also in this part: echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Stored in: " . $_FILES["file"]["tmp_name"]; It shows nothing. That means it didn't upload it and something is maybe wrong with my temp upload dir, but i use GoDaddy Shared Hosting and i don't have a php.ini file on the root (so it uses the default configs) and i cannot change the directory, but i used ini_get() and found out it's /tmp and the path to my actual site is: /home/content/f/a/b/XXXX/html/ So it is even before the 'home' directory and i cannot access that. Anyways: 1. There is something wrong with my script and please help me fix it 2. Can anyone give a php.ini file with all the default configs set so i can change them after. Quote Link to comment Share on other sites More sharing options...
Fabis94 Posted April 5, 2009 Author Share Posted April 5, 2009 Oh cmon can't be no one knows what to do. I tried to find out for more than 3 hours and couldn't understand. Quote Link to comment Share on other sites More sharing options...
unrelenting Posted April 5, 2009 Share Posted April 5, 2009 That means you have to enter the location like this: /home/content/f/a/b/fabis94/ The script is checking for a forward slash before and after the inputted location. If it doesn't have that then it gives you that error. Quote Link to comment Share on other sites More sharing options...
unrelenting Posted April 5, 2009 Share Posted April 5, 2009 Also, make sure that $def_path is equal to /home/content/f/a/b/XXXX/html I added this line to the top of your script and it moved the file correctly (using my own filepath, of course): $def_path = "/home/content/f/a/b/XXXX/html"; Quote Link to comment Share on other sites More sharing options...
Fabis94 Posted April 5, 2009 Author Share Posted April 5, 2009 I don't understand. At the beginning of my PHP script i already have: $def_path = '/home/content/f/a/b/fabis94/html'; Also if you're talking about the location that is $upload_dir then it's the directory where the file should be uploaded (you select your file, write in the directory where it should be uploaded and press UPLOAD). And the error i mentioned before is because of this thing. Also it says "Page already exists in this directory." not the error i mentioned before (sorry). And the error happens if the directory chosen doesn't end OR/AND start with '/' or if the directory is '/' (root) it doesn't give any errors. But it does! Also here is the WHOLE script (i gave u the uploading part only, but this part has also MAKING a new php file not uploading it) maybe something is interfering with something. <?php $htmlstart = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> </body> </html>'; $def_path = "/home/content/f/a/b/fabis94/html"; if (isset($_POST['name_added_get'])) { //Checks if the name is already set from the INDEX page if ($_POST['folder_location'] != '/') { if (substr($_POST['folder_location'], -1) != '/' || substr($_POST['folder_location'], 0, 1) != '/') { echo '<script language"text/javascript">alert("Folder Location must start and end with /");</script>'; echo '<script type="text/javascript">window.location="newpage.php";</script>'; exit; } } if (substr($_POST['phpname'], -1) == '/' || substr($_POST['phpname'], 0, 1) == '/') { echo '<script language"text/javascript">alert("Page name must not start or end with /");</script>'; echo '<script type="text/javascript">window.location="newpage.php";</script>'; exit; } $dom_path = 'http://www.mechtopia.net' . substr($_POST['folder_location'], -$a) . $_POST['phpname'] . '.php'; if (file_exists($def_path . $_POST['folder_location'])) {//ABC: /home/content/f/a/b/fabis94/html $filepath = $def_path . $_POST['folder_location'] . $_POST['phpname'] . '.php'; if (!file_exists($filepath)) {//If PHPNAME doesn't and FOLDERLOCATION exists $fopen = fopen($filepath, "w"); fwrite($fopen, $htmlstart); fclose($fopen); echo '<form action="newpage.php" method="post">'; echo 'Write the contents of the page: <br>'; echo '<center><textarea name="page_contents" cols="60" rows="10">' . file_get_contents($filepath) . '</textarea>'; echo '<input name="h_filepath" type="hidden" value="' . $filepath . '"/>'; $dom_path = 'http://www.mechtopia.net' . substr($_POST['folder_location'], -$a) . $_POST['phpname'] . '.php'; echo '<input name="dom_path" type="hidden" value="' . $dom_path . '"/>'; echo '<br><input value="Write contents to the page!" name="write_cont" type="submit" />'; echo '</form>'; } else { echo '<font color="red">Page already exists in the specified directory.</font>'; }//PHPNAME Exists IF ends here } else { echo '<font color="red">The directory you specified doesnt exist.</font>'; }//FOLDERLOCATION Exists IF ends here } if (isset($_POST['write_cont'])) { //If contents are ready being added - INDEX Method $opened_page = fopen($_POST['h_filepath'], "w") or die('Could not open the page that was made before.'); fwrite($opened_page, $_POST['page_contents']) or die('Could not write into the file.'); fclose($opened_page); echo '<script type="text/javascript">window.location="' . $_POST['dom_path'] . '";</script>'; } /*---------------------------INDEX Method Ends Here---------------------------------*/ if (!isset($_POST['name_added_get']) && !isset($_POST['write_cont']) && !isset($_POST['second_method'])) { echo '<form action="newpage.php" method="post"><b>Create a new page - Enter its name (without .php):</b> '; echo '<input name="phpname2" type="text" size="15" maxlength="10" />'; echo '<br /><b>Write in the folder where it should be saved*:</b> <input name="folder_location2" type="text" value="/" size="15">'; echo '<br>*Root of the server is "/" so if you want to save it on a folder called PHP, write "/PHP/".'; echo ' Always add the end-slash.<br><br><br><br>'; echo '<center><b>Write in the contents of the file:</b> '; echo '<textarea name="page_contents2" cols="60" rows="10">' . $htmlstart . '</textarea>'; echo '<br><input name="second_method" type="submit" /></center>'; } if (isset($_POST['second_method'])) {//Second Methods last part if ($_POST['folder_location2'] != '/') { if (substr($_POST['folder_location2'], -1) != '/' || substr($_POST['folder_location2'], 0, 1) != '/') { echo '<script language"text/javascript">alert("Folder Location must start and end with /");</script>'; echo '<script type="text/javascript">window.location="newpage.php";</script>'; exit; } } if (substr($_POST['phpname2'], -1) == '/' || substr($_POST['phpname2'], 0, 1) == '/') { echo '<script language"text/javascript">alert("Page name must not start or end with /");</script>'; echo '<script type="text/javascript">window.location="newpage.php";</script>'; exit; } $dom_path2 = 'http://www.mechtopia.net' . substr($_POST['folder_location2'], -$a) . $_POST['phpname2'] . '.php'; if (file_exists($def_path . $_POST['folder_location2'])) {//ABC: /home/content/f/a/b/fabis94/html $filepath = $def_path . $_POST['folder_location2'] . $_POST['phpname2'] . '.php'; if (!file_exists($filepath)) {//If PHPNAME doesn't and FOLDERLOCATION exists $dom_path2 = 'http://www.mechtopia.net' . substr($_POST['folder_location2'], -$a) . $_POST['phpname2'] . '.php'; $fopen2 = fopen($filepath, "w"); fwrite($fopen2, $_POST['page_contents2']); fclose($fopen2); echo '<script type="text/javascript">window.location="' . $dom_path2 . '";</script>'; } else { echo '<script language"text/javascript">alert("Page already exists in the specified directory");</script>'; echo '<script type="text/javascript">window.location="newpage.php";</script>'; exit; }//PHPNAME Exists IF ends here } else { echo '<script language"text/javascript">alert("The directory you specified doesnt exist");</script>'; echo '<script type="text/javascript">window.location="newpage.php";</script>'; exit; }//FOLDERLOCATION Exists IF ends here }/*----------------------------------2nd Method Ends here---------------------------------*/ if (!isset($_POST['name_added_get']) && !isset($_POST['write_cont']) && !isset($_POST['second_method'])) { echo '<br><br><hr>You can also upload a page instead of making a new one. Select the file below, select its destination '; echo 'and press "Upload File"<br>'; echo "<form action='upload_file.php' method='post'"; echo "enctype='multipart/form-data'>"; echo "<label for='file'>Filename:</label>"; echo "<input type='file' name='file' id='file' />"; echo "<br /><input type='hidden' name='MAX_FILE_SIZE' value='30000' /><br><input name='upload_dir' type='text' value='/' />"; echo "<input type='submit' name='upload' value='Submit' />"; echo "</form>"; if (isset($_POST['upload'])) {//If Upload Button is Pressed $upload_dir = $_POST['upload_dir']; if ($_POST['upload_dir'] != '/') { if (substr($_POST['upload_dir'], -1) != '/' || substr($_POST['upload_dir'], 0, 1) != '/') { echo '<script language"text/javascript">alert("Folder Location must start and end with /");</script>'; echo '<script type="text/javascript">window.location="newpage.php";</script>'; exit; } }//Correct Folder IF Ends if (file_exists($def_path . $_POST['upload_dir'])) {//ABC: /home/content/f/a/b/fabis94/html $filepath = $def_path . $_POST['upload_dir'] . basename($_FILES["file"]["name"]); $filename = basename($_FILES["file"]["name"]); echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Stored in: " . $_FILES["file"]["tmp_name"]; echo "Errors(?): " . $_FILES["file"]["error"]; echo 'Up dir: ' . $_POST['upload_dir'] . ' Original Basename: ' . $_FILES["file"]["name"] . 'Filepath: ' . $filepath . ' <br>'; if (!file_exists($filepath)) {//If PHPNAME doesn't and FOLDERLOCATION exists if (substr($filename, -4) == '.php') {//If it is a PHP file if (move_uploaded_file($_FILES["file"]["tmp_name"], $filepath)) { echo "<br><font color='green'>File is valid, and was successfully uploaded.</font>\n"; } else { echo "<br><font color='red'>Couldn't upload and move.</font>\n"; } } else { echo '<script language"text/javascript">alert("File must be .PHP");</script>'; echo '<script type="text/javascript">window.location="newpage.php";</script>'; } } else { echo '<script language"text/javascript">alert("Page already exists in the specified directory");</script>'; /*echo '<script type="text/javascript">window.location="newpage.php";</script>';*/ exit; }//PHPNAME Exists IF ends here } else { echo '<script language"text/javascript">alert("The directory you specified doesnt exist");</script>'; echo '<script type="text/javascript">window.location="newpage.php";</script>'; exit; }//FOLDERLOCATION Exists IF ends here }//Upload Button IF ends }//Upload method ends ?> Quote Link to comment Share on other sites More sharing options...
Fabis94 Posted April 5, 2009 Author Share Posted April 5, 2009 I don't understand. At the beginning of my PHP script i already have: $def_path = '/home/content/f/a/b/fabis94/html'; Also if you're talking about the location that is $upload_dir then it's the directory where the file should be uploaded (you select your file, write in the directory where it should be uploaded and press UPLOAD). And the error i mentioned before is because of this thing. Also it says "Page already exists in this directory." not the error i mentioned before (sorry). And the error happens if the directory chosen doesn't end OR/AND start with '/' or if the directory is '/' (root) it doesn't give any errors. But it does! Also here is the WHOLE script (i gave u the uploading part only, but this part has also MAKING a new php file not uploading it) maybe something is interfering with something. <?php $htmlstart = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> </body> </html>'; $def_path = "/home/content/f/a/b/fabis94/html"; if (isset($_POST['name_added_get'])) { //Checks if the name is already set from the INDEX page if ($_POST['folder_location'] != '/') { if (substr($_POST['folder_location'], -1) != '/' || substr($_POST['folder_location'], 0, 1) != '/') { echo '<script language"text/javascript">alert("Folder Location must start and end with /");</script>'; echo '<script type="text/javascript">window.location="newpage.php";</script>'; exit; } } if (substr($_POST['phpname'], -1) == '/' || substr($_POST['phpname'], 0, 1) == '/') { echo '<script language"text/javascript">alert("Page name must not start or end with /");</script>'; echo '<script type="text/javascript">window.location="newpage.php";</script>'; exit; } $dom_path = 'http://XXX' . substr($_POST['folder_location'], -$a) . $_POST['phpname'] . '.php'; if (file_exists($def_path . $_POST['folder_location'])) {//ABC: /home/content/f/a/b/fabis94/html $filepath = $def_path . $_POST['folder_location'] . $_POST['phpname'] . '.php'; if (!file_exists($filepath)) {//If PHPNAME doesn't and FOLDERLOCATION exists $fopen = fopen($filepath, "w"); fwrite($fopen, $htmlstart); fclose($fopen); echo '<form action="newpage.php" method="post">'; echo 'Write the contents of the page: <br>'; echo '<center><textarea name="page_contents" cols="60" rows="10">' . file_get_contents($filepath) . '</textarea>'; echo '<input name="h_filepath" type="hidden" value="' . $filepath . '"/>'; $dom_path = 'http://www.yus.net' . substr($_POST['folder_location'], -$a) . $_POST['phpname'] . '.php'; echo '<input name="dom_path" type="hidden" value="' . $dom_path . '"/>'; echo '<br><input value="Write contents to the page!" name="write_cont" type="submit" />'; echo '</form>'; } else { echo '<font color="red">Page already exists in the specified directory.</font>'; }//PHPNAME Exists IF ends here } else { echo '<font color="red">The directory you specified doesnt exist.</font>'; }//FOLDERLOCATION Exists IF ends here } if (isset($_POST['write_cont'])) { //If contents are ready being added - INDEX Method $opened_page = fopen($_POST['h_filepath'], "w") or die('Could not open the page that was made before.'); fwrite($opened_page, $_POST['page_contents']) or die('Could not write into the file.'); fclose($opened_page); echo '<script type="text/javascript">window.location="' . $_POST['dom_path'] . '";</script>'; } /*---------------------------INDEX Method Ends Here---------------------------------*/ if (!isset($_POST['name_added_get']) && !isset($_POST['write_cont']) && !isset($_POST['second_method'])) { echo '<form action="newpage.php" method="post"><b>Create a new page - Enter its name (without .php):</b> '; echo '<input name="phpname2" type="text" size="15" maxlength="10" />'; echo '<br /><b>Write in the folder where it should be saved*:</b> <input name="folder_location2" type="text" value="/" size="15">'; echo '<br>*Root of the server is "/" so if you want to save it on a folder called PHP, write "/PHP/".'; echo ' Always add the end-slash.<br><br><br><br>'; echo '<center><b>Write in the contents of the file:</b> '; echo '<textarea name="page_contents2" cols="60" rows="10">' . $htmlstart . '</textarea>'; echo '<br><input name="second_method" type="submit" /></center>'; } if (isset($_POST['second_method'])) {//Second Methods last part if ($_POST['folder_location2'] != '/') { if (substr($_POST['folder_location2'], -1) != '/' || substr($_POST['folder_location2'], 0, 1) != '/') { echo '<script language"text/javascript">alert("Folder Location must start and end with /");</script>'; echo '<script type="text/javascript">window.location="newpage.php";</script>'; exit; } } if (substr($_POST['phpname2'], -1) == '/' || substr($_POST['phpname2'], 0, 1) == '/') { echo '<script language"text/javascript">alert("Page name must not start or end with /");</script>'; echo '<script type="text/javascript">window.location="newpage.php";</script>'; exit; } $dom_path2 = 'http://www.yus.net' . substr($_POST['folder_location2'], -$a) . $_POST['phpname2'] . '.php'; if (file_exists($def_path . $_POST['folder_location2'])) {//ABC: /home/content/f/a/b/fabis94/html $filepath = $def_path . $_POST['folder_location2'] . $_POST['phpname2'] . '.php'; if (!file_exists($filepath)) {//If PHPNAME doesn't and FOLDERLOCATION exists $dom_path2 = 'http://www.yus.net' . substr($_POST['folder_location2'], -$a) . $_POST['phpname2'] . '.php'; $fopen2 = fopen($filepath, "w"); fwrite($fopen2, $_POST['page_contents2']); fclose($fopen2); echo '<script type="text/javascript">window.location="' . $dom_path2 . '";</script>'; } else { echo '<script language"text/javascript">alert("Page already exists in the specified directory");</script>'; echo '<script type="text/javascript">window.location="newpage.php";</script>'; exit; }//PHPNAME Exists IF ends here } else { echo '<script language"text/javascript">alert("The directory you specified doesnt exist");</script>'; echo '<script type="text/javascript">window.location="newpage.php";</script>'; exit; }//FOLDERLOCATION Exists IF ends here }/*----------------------------------2nd Method Ends here---------------------------------*/ if (!isset($_POST['name_added_get']) && !isset($_POST['write_cont']) && !isset($_POST['second_method'])) { echo '<br><br><hr>You can also upload a page instead of making a new one. Select the file below, select its destination '; echo 'and press "Upload File"<br>'; echo "<form action='upload_file.php' method='post'"; echo "enctype='multipart/form-data'>"; echo "<label for='file'>Filename:</label>"; echo "<input type='file' name='file' id='file' />"; echo "<br /><input type='hidden' name='MAX_FILE_SIZE' value='30000' /><br><input name='upload_dir' type='text' value='/' />"; echo "<input type='submit' name='upload' value='Submit' />"; echo "</form>"; if (isset($_POST['upload'])) {//If Upload Button is Pressed $upload_dir = $_POST['upload_dir']; if ($_POST['upload_dir'] != '/') { if (substr($_POST['upload_dir'], -1) != '/' || substr($_POST['upload_dir'], 0, 1) != '/') { echo '<script language"text/javascript">alert("Folder Location must start and end with /");</script>'; echo '<script type="text/javascript">window.location="newpage.php";</script>'; exit; } }//Correct Folder IF Ends if (file_exists($def_path . $_POST['upload_dir'])) {//ABC: /home/content/f/a/b/fabis94/html $filepath = $def_path . $_POST['upload_dir'] . basename($_FILES["file"]["name"]); $filename = basename($_FILES["file"]["name"]); echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Stored in: " . $_FILES["file"]["tmp_name"]; echo "Errors(?): " . $_FILES["file"]["error"]; echo 'Up dir: ' . $_POST['upload_dir'] . ' Original Basename: ' . $_FILES["file"]["name"] . 'Filepath: ' . $filepath . ' <br>'; if (!file_exists($filepath)) {//If PHPNAME doesn't and FOLDERLOCATION exists if (substr($filename, -4) == '.php') {//If it is a PHP file if (move_uploaded_file($_FILES["file"]["tmp_name"], $filepath)) { echo "<br><font color='green'>File is valid, and was successfully uploaded.</font>\n"; } else { echo "<br><font color='red'>Couldn't upload and move.</font>\n"; } } else { echo '<script language"text/javascript">alert("File must be .PHP");</script>'; echo '<script type="text/javascript">window.location="newpage.php";</script>'; } } else { echo '<script language"text/javascript">alert("Page already exists in the specified directory");</script>'; /*echo '<script type="text/javascript">window.location="newpage.php";</script>';*/ exit; }//PHPNAME Exists IF ends here } else { echo '<script language"text/javascript">alert("The directory you specified doesnt exist");</script>'; echo '<script type="text/javascript">window.location="newpage.php";</script>'; exit; }//FOLDERLOCATION Exists IF ends here }//Upload Button IF ends }//Upload method ends ?> Don't mind the different domain names they are all the same in the real script. *Ooops sorry for double post. Mistook modify with Quote. Also the error happens if (!file_exists($filepath)) and $filepath is $filepath = $def_path . $_POST['upload_dir'] . basename($_FILES["file"]["name"]); But as it later says at "Upload: " . $_FILES["file"]["name"] Upload: (nothing) That means it didn't even get the file. Also i added echo "Errors(?): " . $_FILES["file"]["error"]; and it returned nothing too. Quote Link to comment Share on other sites More sharing options...
Fabis94 Posted April 5, 2009 Author Share Posted April 5, 2009 Oh i understand what you meant, but the problem is $def_path already is set like that and the error isn't the one i mentioned in the first post sorry. So can anyone help? *I can't edit the other post (no Edit option) Quote Link to comment Share on other sites More sharing options...
Fabis94 Posted April 6, 2009 Author Share Posted April 6, 2009 Seriously no one can help? Quote Link to comment 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.