suess0r Posted May 15, 2007 Share Posted May 15, 2007 Hi, I'm trying to get to upload documents to a directory on my server. I'm getting some No Directory Found errors that I think has a lot to do with how I run my include statement... here's what I got <?php include ($_SERVER['DOCUMENT_ROOT']."/classes/upload/upload_class.php"); //classes is the map where the class file is stored (one above the root) $max_size = 1024*250; // the max. size for uploading $my_upload = new file_upload; $my_upload->upload_dir = $_SERVER['DOCUMENT_ROOT']."/files/new/"; // "files" is the folder for the uploaded files (you have to create this folder) $my_upload->extensions = array(".png", ".zip", ".pdf", ".doc"); // specify the allowed extensions here // $my_upload->extensions = "de"; // use this to switch the messages into an other language (translate first!!!) $my_upload->max_length_filename = 50; // change this value to fit your field length in your database (standard 100) $my_upload->rename_file = true; if(isset($_POST['Submit'])) { $my_upload->the_temp_file = $_FILES['upload']['tmp_name']; $my_upload->the_file = $_FILES['upload']['name']; $my_upload->http_error = $_FILES['upload']['error']; $my_upload->replace = (isset($_POST['replace'])) ? $_POST['replace'] : "n"; // because only a checked checkboxes is true $my_upload->do_filename_check = (isset($_POST['check'])) ? $_POST['check'] : "n"; // use this boolean to check for a valid filename $new_name = (isset($_POST['name'])) ? $_POST['name'] : ""; if ($my_upload->upload($new_name)) { // new name is an additional filename information, use this to rename the uploaded file $full_path = $my_upload->upload_dir.$my_upload->file_copy; $info = $my_upload->get_uploaded_file_info($full_path); // ... or do something like insert the filename to the database } } ?> OK so that's at the top of my php page and here's the call to browse the computer for the file and the submit button <form name="form1" enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_size; ?>"><br> <label for="upload">Select a file...</label><input type="file" name="upload" size="30"><br clear="all"> <label for="name"></label> <br clear="all"> <input style="margin-left:120px;" type="submit" name="Submit" value="Submit"> </form> <br clear="all"> <p><?php echo $my_upload->show_error_string(); ?></p> <?php if (isset($info)) echo "<blockquote>".nl2br($info)."</blockquote>"; ?> OK, so basically everything should work (I can post the php for the classes if need be) but all that's happening is I'm getting the following error messages at the top header.. Warning: mkdir(/home/content/s/u/e/suess0r/html/files/new/): No such file or directory in /home/content/s/u/e/suess0r/html/classes/upload/upload_class.php on line 150 Warning: move_uploaded_file(/home/content/s/u/e/suess0r/html/files/new/1179204404.doc): failed to open stream: No such file or directory in /home/content/s/u/e/suess0r/html/classes/upload/upload_class.php on line 130 Warning: move_uploaded_file(): Unable to move '/tmp/phpkl0kMe' to '/home/content/s/u/e/suess0r/html/files/new/1179204404.doc' in /home/content/s/u/e/suess0r/html/classes/upload/upload_class.php on line 130 I'm thinking that it has a lot to do with ($_SERVER['DOCUMENT_ROOT']."/classes/upload/upload_class.php") - I have the upload_class.php in /classes/upload/ but something's not going right with the $_SERVER['DOCUMENT_ROOT']. Can anyone shed some light on how I need to be calling this class that would work? Can I do an include without the $_SERVER['DOCUMENT_ROOT']? Appreciate everything, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/51437-upload-to-directory-problems-with-include-in-header/ Share on other sites More sharing options...
radar Posted May 15, 2007 Share Posted May 15, 2007 I generally don't use Document_Root for anything... Say I have a server setup similar to this.. Root -> templates --> default ---> admin ---> forums ---> site ---> images --> ADMIN --->index.php --- note that this is a real folder setup for the site I am currently working on which is a multi template site (can be changed)... instead of doing document_root."/templates/default/admin/blah.tpl" I would simply do something like ../templates/default/admin/blah.tpl instead... ../ takes you one folder back so say my index.php was 4 folders in... I would do something like ../../../../templates/default/admin/blah.tpl in order to get it to work... if this isnt what you're wondering let me know.. i'd love to help out. Quote Link to comment https://forums.phpfreaks.com/topic/51437-upload-to-directory-problems-with-include-in-header/#findComment-253323 Share on other sites More sharing options...
suess0r Posted May 15, 2007 Author Share Posted May 15, 2007 Hey, thanks for your reply... I tried adding the up directory ../ instead of the document root but it wasn't able to work. Everything works on the original with the Document root but for some reason it still gives me this error Warning: mkdir(/home/content/s/u/e/suess0r/html/files/new/): No such file or directory in /home/content/s/u/e/suess0r/html/classes/upload/upload_class.php on line 150 Warning: move_uploaded_file(/home/content/s/u/e/suess0r/html/files/new/1179210670.doc): failed to open stream: No such file or directory in /home/content/s/u/e/suess0r/html/classes/upload/upload_class.php on line 130 Warning: move_uploaded_file(): Unable to move '/tmp/phpnfnrMT' to '/home/content/s/u/e/suess0r/html/files/new/1179210670.doc' in /home/content/s/u/e/suess0r/html/classes/upload/upload_class.php on line 130 Maybe I'm missing something but here's the directory structure so maybe we can work something out with the Include ../ index.php /upload/upload_class.php I tried include this include "../classes/upload/upload_class.php"; but got these errors before the page even loaded Warning: main(../classes/upload/upload_class.php): failed to open stream: No such file or directory in /home/content/s/u/e/suess0r/html/newupload.php on line 2 Warning: main(../classes/upload/upload_class.php): failed to open stream: No such file or directory in /home/content/s/u/e/suess0r/html/newupload.php on line 2 Warning: main(): Failed opening '../classes/upload/upload_class.php' for inclusion (include_path='.:/usr/local/lib/php') in /home/content/s/u/e/suess0r/html/newupload.php on line 2 Fatal error: Cannot instantiate non-existent class: file_upload in /home/content/s/u/e/suess0r/html/newupload.php on line 6 Quote Link to comment https://forums.phpfreaks.com/topic/51437-upload-to-directory-problems-with-include-in-header/#findComment-253343 Share on other sites More sharing options...
radar Posted May 15, 2007 Share Posted May 15, 2007 Looks like your main problem is just getting upload_class.php included... i bet that once you get that included correctly it'll actually work -- so work on that part.. So if your directory structure is like this.. --Root -- index.php --> upload ---> upload_class.php try doing this.. include "/upload/upload_class.php"; instead of any ../ or anything see if that works... Quote Link to comment https://forums.phpfreaks.com/topic/51437-upload-to-directory-problems-with-include-in-header/#findComment-253344 Share on other sites More sharing options...
suess0r Posted May 15, 2007 Author Share Posted May 15, 2007 OK, got it! I moved the actual index.php file to the same directory as the upload_class.php and got everything working. I appreciate the help, thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/51437-upload-to-directory-problems-with-include-in-header/#findComment-253354 Share on other sites More sharing options...
radar Posted May 15, 2007 Share Posted May 15, 2007 That works too -- I figured there was an issue getting it included, but at least it works -- and remember to hit the link or whatever @ the bottom to mark this as solved.. Quote Link to comment https://forums.phpfreaks.com/topic/51437-upload-to-directory-problems-with-include-in-header/#findComment-253355 Share on other sites More sharing options...
suess0r Posted May 15, 2007 Author Share Posted May 15, 2007 1 more thing... So, I uploaded the file to a specific directory right? Now, I want my client (who the site is for) to be able to login to that directory to see any of the new documents that got uploaded... how do I go about accessing those files without her having to FTP in? I tried just going to the directory on the page but I get a 404 error. I also have never been able to find a decent login script, does anyone have anything they can recommend? The simpler the better. Quote Link to comment https://forums.phpfreaks.com/topic/51437-upload-to-directory-problems-with-include-in-header/#findComment-253357 Share on other sites More sharing options...
radar Posted May 15, 2007 Share Posted May 15, 2007 Here is a basic login script for you.. <?php if ($_SESSION['admin']['intime'] != '') { if ($_SESSION['admin']['intime'] < time() - 1800) { session_unset('admin'); $over = "1800"; echo "ERROR: you have been idle for more than 1800 seconds. Please login again"; }} $_action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; switch ($_action) { default: if (!isset($_SESSION['admin'])) { if ($over != "1800") { echo 'Authorization Required. Please log in.' } // login form html here } else { include of the page you wish to show } break; case login: if ($_REQUEST['act'] != "login") { if (isset($_SESSION['admin']) ) { // update session } if ($_SESSION['admin']['username'] != '') { // include of the page you want to view } else { if ($over != "1800") { echo "authorization required"; } // login form include } } else { // the query to the database, (use LIKE BINARY for case sensitivity) // also the cookie/session creation would go here if ($login == "true") { // show the actual page you want them to view } else { // show the login form } } break; } ?> // edit: edited the code i forgot a } at the end Okay so its a little more than basic, but boy it works wonders! Quote Link to comment https://forums.phpfreaks.com/topic/51437-upload-to-directory-problems-with-include-in-header/#findComment-253363 Share on other sites More sharing options...
suess0r Posted May 15, 2007 Author Share Posted May 15, 2007 Great, thanks! Any thoughts on what I should do about my client being able to access the directory without FTP? Quote Link to comment https://forums.phpfreaks.com/topic/51437-upload-to-directory-problems-with-include-in-header/#findComment-253367 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.