philipsbe Posted March 16, 2011 Share Posted March 16, 2011 I need to process a CSV file in database (MySql using LOAD DATA INFILE)), while the code is working fine but it works only with file that is already on my apache server (where php is installed). Is there any way (Java/Ajax or anything) that I can prompt user to select a file from any loaction they prefer including there desktop?? Thanks in advance!! Quote Link to comment https://forums.phpfreaks.com/topic/230870-prompt-for-a-filename/ Share on other sites More sharing options...
cunoodle2 Posted March 17, 2011 Share Posted March 17, 2011 It comes with great honor that this is my 700th post. As a result I will try to make it extra special. First you need a form to allow for a file upload. Here is the html code for that portion.. <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> Then you need the php to process said file upload.. <?php // Where the file is going to be placed $target_path = "uploads/"; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $target_path = "uploads/"; $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!"; } ?> You can read more about this from this very very useful tutorial.. http://www.tizag.com/phpT/fileupload.php Quote Link to comment https://forums.phpfreaks.com/topic/230870-prompt-for-a-filename/#findComment-1188571 Share on other sites More sharing options...
philipsbe Posted March 17, 2011 Author Share Posted March 17, 2011 Thanks Cunoodle, i am going to try this out. Quote Link to comment https://forums.phpfreaks.com/topic/230870-prompt-for-a-filename/#findComment-1188719 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.