Martinfin Posted April 30, 2010 Share Posted April 30, 2010 This is what I basically got... <?php // upload.php echo <<<_END <html><head><title>PHP Form Upload</title></head><body> <form method='post' action='upload.php' enctype='multipart/form-data'> Select File: <input type='file' name='filename' size='10' /> <input type='submit' value='Upload' /> </form> _END; if ($_FILES) { $name = $_FILES['filename']['name']; move_uploaded_file($_FILES['filename']['tmp_name'], $name); echo "Uploaded File '$name'<br /><img src='$name' />"; } echo "</body></html>"; ?> What I am wanting to do with this is: Make the file go directly in my Folder called "Files" but instead it goes directly in the main htdocs folder.... Can anyone help me understand how to alter this to make it go to the files folder?? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/200318-upload-forum-help/ Share on other sites More sharing options...
Lamez Posted April 30, 2010 Share Posted April 30, 2010 add "/files/". to name. like so $name = "/files/".$_FILES['filename']['name']; or wait do this instead: $name = $_FILES['filename']['name']; $folder = "/files/".$_FILES['filename']['name']; move_uploaded_file($_FILES['filename']['tmp_name'], $folder); Quote Link to comment https://forums.phpfreaks.com/topic/200318-upload-forum-help/#findComment-1051262 Share on other sites More sharing options...
Martinfin Posted May 1, 2010 Author Share Posted May 1, 2010 add "/files/". to name. like so $name = "/files/".$_FILES['filename']['name']; or wait do this instead: $name = $_FILES['filename']['name']; $folder = "/files/".$_FILES['filename']['name']; move_uploaded_file($_FILES['filename']['tmp_name'], $folder); I appreciate your help me but when I added this it still goes to the same place like nothing was even changed. Look to see if I messed it up if you don't mind... <?php // upload.php echo <<<_END <html><head><title>PHP Form Upload</title></head><body> <form method='post' action='upload.php' enctype='multipart/form-data'> Select File: <input type='file' name='filename' size='10' /> <input type='submit' value='Upload' /> </form> _END; if ($_FILES) { $name = $_FILES['filename']['name']; $folder = "/files/".$_FILES['filename']['name']; move_uploaded_file($_FILES['filename']['tmp_name'], $folder); } echo "</body></html>"; ?> Also I'm assuming you could try this out.. If so, Let me know if it worked for you and if it did.. maybe I just have no idea what I'm doing.. Quote Link to comment https://forums.phpfreaks.com/topic/200318-upload-forum-help/#findComment-1051310 Share on other sites More sharing options...
Martinfin Posted May 1, 2010 Author Share Posted May 1, 2010 Could find the EDIT button on this Page, I wanted to add, Here is what happens... Warning: move_uploaded_file(/files/readme.txt) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\xampplite\htdocs\upload.php on line 14 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampplite\tmp\php2208.tmp' to '/files/readme.txt' in C:\xampplite\htdocs\upload.php on line 14 And yea, I'm using xampplite... I'm very new to this all but I catch on quick. Quote Link to comment https://forums.phpfreaks.com/topic/200318-upload-forum-help/#findComment-1051317 Share on other sites More sharing options...
ChemicalBliss Posted May 1, 2010 Share Posted May 1, 2010 $folder = "/files/".$_FILES['filename']['name']; Using a forward sash at the start mens - start from ROOT of device. EG, C:. terefore your askingit to move the file to: C:/files/file.name Use a ./ instead of a / eg: $folder = "./files/".$_FILES['filename']['name']; -cb- Quote Link to comment https://forums.phpfreaks.com/topic/200318-upload-forum-help/#findComment-1051319 Share on other sites More sharing options...
Martinfin Posted May 1, 2010 Author Share Posted May 1, 2010 Well, This did help... No more errors. But, I get -> "No file chosen" hmmmm Quote Link to comment https://forums.phpfreaks.com/topic/200318-upload-forum-help/#findComment-1051328 Share on other sites More sharing options...
ChemicalBliss Posted May 1, 2010 Share Posted May 1, 2010 Where are you getting that from? Try uploading a file again, a small file, a .txt file or something. If the code you posted earlier worked for you then this should too, your original post should be changed: $name = $_FILES['filename']['name']; to $name = './files/'.$_FILES['filename']['name']; -cb- Quote Link to comment https://forums.phpfreaks.com/topic/200318-upload-forum-help/#findComment-1051334 Share on other sites More sharing options...
Martinfin Posted May 1, 2010 Author Share Posted May 1, 2010 Where are you getting that from? Try uploading a file again, a small file, a .txt file or something. If the code you posted earlier worked for you then this should too, your original post should be changed: $name = $_FILES['filename']['name']; to $name = './files/'.$_FILES['filename']['name']; -cb- Omg, Thank you so much... This works... I wasn't thinking that I didn't put in anything to let me know Upload completed. But your help was and still is ver much appreciated. Thanks goes to ChemicalBliss and Lamez!!! This topic can be closed but don't delete incase someone else has the same problem... Take care man! Quote Link to comment https://forums.phpfreaks.com/topic/200318-upload-forum-help/#findComment-1051338 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.