Jump to content

Prompt for a filename


philipsbe

Recommended Posts

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!!

 

 

Link to comment
https://forums.phpfreaks.com/topic/230870-prompt-for-a-filename/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.