lorne17 Posted August 13, 2008 Share Posted August 13, 2008 Hello there, I have been working on getting an index.php page set up to show the list of files in a specified folder. Now I am trying to get an upload files option to go into that same folder. Then if you hit refresh, the new file that was "successfully" uploaded will be in that list. Here's the code I have to generate the list. It works great. <?php if ($handle = opendir('.')) { $ignore_files = array('.', '..', '.htaccess', '.htpasswd', 'index.php'); while (false !== ($file = readdir($handle))) { if (!in_array($file, $ignore_files)) { $thelist .= '<a href="'.$file.'">'.$file.'</a>'.'<br>'; } } closedir($handle); } ?> <p style="font-weight: bold; font-size: 10pt">List of files:</p> <p style="font-weight: bold; font-size: 10pt; color: #560D1C"><?=$thelist?></p> Now I need to add more code to upload files. Thanks, Lorne Quote Link to comment https://forums.phpfreaks.com/topic/119561-upload-files-to-same-folder-as-indexphp/ Share on other sites More sharing options...
trq Posted August 13, 2008 Share Posted August 13, 2008 And your question is? Quote Link to comment https://forums.phpfreaks.com/topic/119561-upload-files-to-same-folder-as-indexphp/#findComment-615961 Share on other sites More sharing options...
ignace Posted August 13, 2008 Share Posted August 13, 2008 we are very happy that you are letting us know that you have achieved such great things.. Quote Link to comment https://forums.phpfreaks.com/topic/119561-upload-files-to-same-folder-as-indexphp/#findComment-615962 Share on other sites More sharing options...
lorne17 Posted August 13, 2008 Author Share Posted August 13, 2008 You really don't understand the question? Ok let me be more clear sorry about that... How do I add PHP coding to allow users to upload files to the same directory that the index.php file is located?? Does that help?? sorry again. Quote Link to comment https://forums.phpfreaks.com/topic/119561-upload-files-to-same-folder-as-indexphp/#findComment-615963 Share on other sites More sharing options...
trq Posted August 13, 2008 Share Posted August 13, 2008 Have you tried searching for tutorials on the subject? A Google search of the term php uploads produces some 876,000 hits. Do you really want use to write another one here especially for you? Quote Link to comment https://forums.phpfreaks.com/topic/119561-upload-files-to-same-folder-as-indexphp/#findComment-615965 Share on other sites More sharing options...
ignace Posted August 13, 2008 Share Posted August 13, 2008 Do you really want use to write another one here especially for you? that's a retorical question on this forum, you know that? why do you think he posted? Quote Link to comment https://forums.phpfreaks.com/topic/119561-upload-files-to-same-folder-as-indexphp/#findComment-615973 Share on other sites More sharing options...
lorne17 Posted August 13, 2008 Author Share Posted August 13, 2008 Well while you guys crack yourselves up...I tried some of the tutorials and I can't get it to work. Why, hell...I don't know why? That's why I'm posting here. If you're willing to help great. If you're not, then don't say anything, cuz it's pretty annoying. I do appreciate any help anyone can give. I'm sorry i'm a beginner at this PHP stuff and I don't mean to ask dumb questions. So please bear with me. This is the code I put in my index.php page: <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> This is the code I put in my uploader.php page: <!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> <?php // Where the file is going to be placed $target_path = "/"; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $_FILES['uploadedfile']['tmp_name']; $target_path = "/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } ?> </body> </html> Whenever I try to upload a file I get the echo message: "There was an error uploading the file, please try again!" Does anyone know why this is happening? What am I missing? Thanks in advance, Lorne Quote Link to comment https://forums.phpfreaks.com/topic/119561-upload-files-to-same-folder-as-indexphp/#findComment-615982 Share on other sites More sharing options...
trq Posted August 13, 2008 Share Posted August 13, 2008 The problem is likely to do with this... $target_path = "/"; This will make your target directory the root of your servers filesystem, it is highly unlikely apache has permission to write anything there. Place the following at the top of your script to see if we can get more feedback. <?php error_reporting(E_ALL) ; ini_set('display_errors','1'); ?> If you're willing to help great. If you're not, then don't say anything, cuz it's pretty annoying. So is rewriting tutorials that are obviously easy to find. We'll help when you get stuck, but there's no point in duplicating content which is readily available. Quote Link to comment https://forums.phpfreaks.com/topic/119561-upload-files-to-same-folder-as-indexphp/#findComment-616000 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.