Local File Path

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ffcyan
Forum Newbie
Posts: 11
Joined: Thu Oct 07, 2004 3:42 pm

Local File Path

Post by ffcyan »

I am trying to FTP a file on my local drive (c:/...etc) to my remote server. All my code is correct except the local path. How does one reference a file on the local drive? In other words what is the correct syntax?

My code right now reads as follows:

$source_file = 'somefile.txt'

This is obviously incorrect because this says to search for 'somefile.txt' in the same directory as the .php file. Being that the .php file is on the remote server, it will look for 'somefile.txt' on the remote server. Again, I need to know what the code is to take a folder from a local drive. Thank you very much.


Just in case you wanted to see the entire script:

Code: Select all

<?php

// set up basic connection
$ftp_server = '63.135.102.252';
$conn_id = ftp_connect($ftp_server); 
$ftp_user_name = 'user';
$ftp_user_pass = 'pw';
$destination_file = 'newtextfile.txt';
$source_file = 'somefile.txt';


// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 

// check connection
if ((!$conn_id) || (!$login_result)) 
{echo "FTP connection has failed! <br>";
echo "Attempted to connect to $ftp_server for user $ftp_user_name <br>"; 
exit;}

else
{echo "Connected to $ftp_server for user $ftp_user_name <br>";}

// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY); 

// check upload status
if (!$upload) 
{echo "FTP upload has failed!";}
	   
else

{echo "Uploaded $source_file to $ftp_server as $destination_file";}

// close the FTP stream 
ftp_close($conn_id);

?>

NOTE: "user" and "pw" are not the actual user name and password.
hedge
Forum Contributor
Posts: 234
Joined: Fri Aug 30, 2002 10:19 am
Location: Calgary, AB, Canada

Post by hedge »

not possible. PHP runs on the server therefore it can only see files on the server.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You would need to set up a file uploading form to run in tandem with your FTP script, that's the way you would use to choose the local file(s) to upload to the server.

Mac
Post Reply