jeff5656 Posted February 11, 2009 Share Posted February 11, 2009 When I run this, <form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> Send this file: <input name="userfile" type="file" /><br /> <input type="submit" name="submitBtn" value="Send File" /> </form> <?php if (isset($_POST['submitBtn'])){ if (move_uploaded_file($_FILES['userfile']['tmp_name'], "../schedules/")) { echo "The file: ". basename( $_FILES['userfile']['name']) . "has been uploaded"; } else { echo "Upload failed!"; } } ?> I go to the schedules directory, and the file is not there even though I get the message: The file: test.doc has been uploaded Quote Link to comment https://forums.phpfreaks.com/topic/144811-upload-problem/ Share on other sites More sharing options...
grissom Posted February 11, 2009 Share Posted February 11, 2009 You may wish to add an extra line into your form submission code like this : <INPUT TYPE = "HIDDEN" NAME = "MAX_FILE_SIZE" VALUE = "1300000"> put it just before the type="file" line Also, view your source code to see what is being sent down to the browser in your <FORM> statement, check that it's OK. Check your permissions on your /schedules/ subfolder, you may need to add more "write" permissions Also, I think you need to specify more than just the subfolder in your upload statement, I think you need to specify the whole filename right down to the extension try : $final_file_name = '../schedules/' . basename($_FILES['userfile']['name']); if (move_uploaded_file($_FILES['userfile']['tmp_name'], $final_file_name)) { // etc. etc. etc. Lemme know if you tried all that and it doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/144811-upload-problem/#findComment-759895 Share on other sites More sharing options...
jeff5656 Posted February 12, 2009 Author Share Posted February 12, 2009 Yes, you're right - adding the full filename solved it. Thanks. But I wish there was a way to screen an uploaded file for an HTML extension and it it exists, change it to .HTM. I posted that in an earlier post but there was no solution. Any ideas? It "seems" simple enough but my knowledge of php is not quite good enough to pull that off! :-) Quote Link to comment https://forums.phpfreaks.com/topic/144811-upload-problem/#findComment-760638 Share on other sites More sharing options...
premiso Posted February 12, 2009 Share Posted February 12, 2009 $name = basename($_FILES['userfile']['name']); if (file_exists('../schedules/' . $name) && stristr($name, ".HTML")) { $ext = explode(".", $name); $name = str_replace($ext[1], 'HTM', $name); } $final_file_name = '../schedules/' . $name; That should take care of that. Quote Link to comment https://forums.phpfreaks.com/topic/144811-upload-problem/#findComment-760644 Share on other sites More sharing options...
jeff5656 Posted February 12, 2009 Author Share Posted February 12, 2009 Thanks! But a question: where does that go. Is it before or after this section (or replace it): if (move_uploaded_file($_FILES['userfile']['tmp_name'], "../schedules/")) { echo "The file: ". basename( $_FILES['userfile']['name']) . "has been uploaded"; } else { echo "Upload failed!"; } Quote Link to comment https://forums.phpfreaks.com/topic/144811-upload-problem/#findComment-760656 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.