Capturing file path using browse functionality.
Posted: Thu May 06, 2010 11:29 am
All,
Here's my simple code that I want to use on a site to upload a file(s) to the server.
My problem is getting the complete path to the file. For example, if the user wants to copy a file located on a windows machine located at:
c:\pictures\mine\mypic.jpg
the submit will only return the file name, in this case mypic.jpg, and not the entire path. Without the full path the fopen will fail.
My question is: How do I include the entire path using the browse form? This there a better way to go about this?
Here's my simple code that I want to use on a site to upload a file(s) to the server.
Code: Select all
if(isset($_GET['submit']))
{
require('./include/pf_ftp_connect.php');
require('./include/pf_mysqli_connect.php');
$upload = $_GET['uploaded'];
$remotefile = '/web/uploads/'.$upload;
$localfile = $upload;
$fp = fopen ($localfile, 'r');
if (!$success = ftp_fput($conn, $remotefile, $fp, FTP_BINARY))
{
echo 'Error: Could not upload file';
ftp_quit($conn);
exit;
}
fclose($fp);
echo 'File upload successfully';
// close connection to host
ftp_quit($conn);
}
else
{
?>
<form enctype="multipart/form-data" action="image_upload.php" method="GET">
<br /><br>
Please choose a file:
<input name="uploaded" type="file" />
<br /><br />
<input type="submit" name="submit" value="Upload" />
</form>
<?php
echo 'goodbye<br/>';
}
?>
c:\pictures\mine\mypic.jpg
the submit will only return the file name, in this case mypic.jpg, and not the entire path. Without the full path the fopen will fail.
My question is: How do I include the entire path using the browse form? This there a better way to go about this?