Jump to content

FTP Upload Problems


p0werdirector

Recommended Posts

For my website, i need a function to upload a file to my ftp server directly from the website. I dont really know much about php so i googled it, found a code and configurated it. The code now looks like this:

<html>
<head>
</head>
<body>

<form action="ftp.php" enctype="multipart/form-data" method="POST">
<input name="local_file" type="file" size="50" maxlength="1024">

<input type="hidden" value="1" name="flag" />
<input type="submit" name="upload" value="Upload">
</form>


<?php
if(isset($_POST['upload'])){
	$ftp_server = "62.153.19.158";
	$username = "Website";
	$password = "web";
	$file = $HTTP_POST_FILES['local_file']['name'];

	$connection_id = ftp_connect($ftp_server);

	$login_result = ftp_login($connection__id, $username, $password);

	if ((!$connection_id) || (!$login_result)){
		die 'No FTP-Conection established!' <br> 'Connection with FTP-Server as user '. $username . 'not possible!';
	}else{
		echo 'Connected.';
	}

	if(ftp_put($connection_id, $file, $local_file, FTP_ASCII)){
		echo 'Error while uploading!';
	}else{
		echo 'File '. $file .' uploaded on '. $ftp_server .' as '. $file;
	}
	
	ftp_quit($connection_id);
}
?>
</body>
</html>

If i open it up, i just get an error code saying:

Parse error: syntax error, unexpected ''No FTP-Conection established!' (T_CONSTANT_ENCAPSED_STRING) in /home/virtual/test-mediaz.eu/htdocs/Upload.php on line 26

I checked the code a few times and even a friend who knows much more about PHP could not find the problem.

 

I would be very grateful if someone of you could help me with this since it is quite an important project.

 

 

Link to comment
Share on other sites

Please check this lines

$connection_id = ftp_connect($ftp_server);
 
$login_result = ftp_login($connection__id, $username, $password);

variable name $connection_id in second line has tow under scores(__)

 

also update this lines as 

if ((!$connection_id) || (!$login_result)){
	die ("No FTP-Conection established!<br>Connection with FTP-Server as user ".$username." not possible!");
Edited by pbs
Link to comment
Share on other sites

I need multiple users on the website to upload files from their computer to my server. And since there will be a lot of different users, i cant just create a new user for the server for each user. So whoever wants to upload a file, should just open up the website, choose his file and upload it. Without the need to login with his own account. All the uploads from the website should just go over the account "Website" (as it is set in the code).

Link to comment
Share on other sites

ftp.php is the form action you specified, means that all code checking will be performed there.

 

Create a new file named ftp.php in the same directory as the file you used, and add the php code from the document above into it.

 

If you cannot do so, change the <form action="ftp.php"> to <form action="">

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.