Jump to content


Photo

FTP Upload Problems


  • Please log in to reply
13 replies to this topic

#1 p0werdirector

p0werdirector

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 10 May 2013 - 01:34 AM

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.

 

 



#2 PravinS

PravinS

    Advanced Member

  • Members
  • PipPipPip
  • 431 posts
  • LocationNashik, India

Posted 10 May 2013 - 01:40 AM

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, 10 May 2013 - 01:42 AM.

Thanks & Regards,
PravinS | Blog


#3 p0werdirector

p0werdirector

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 10 May 2013 - 01:54 AM

Updated it and the upload form itself works now. But apparently i need a file called ftp.php. what exactly do i have to put into it?



#4 PravinS

PravinS

    Advanced Member

  • Members
  • PipPipPip
  • 431 posts
  • LocationNashik, India

Posted 10 May 2013 - 02:13 AM

What exactly your requirement?

 

If you want to upload/download multiple files from your local machine to server or server to local machine, you can use any FTP client like FILE ZILA, CUTEFTP etc.


Thanks & Regards,
PravinS | Blog


#5 p0werdirector

p0werdirector

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 10 May 2013 - 02:20 AM

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).



#6 PravinS

PravinS

    Advanced Member

  • Members
  • PipPipPip
  • 431 posts
  • LocationNashik, India

Posted 10 May 2013 - 02:38 AM

According to you requirement don't use FTP upload script, you can use simple PHP uploading functions like copy, move_uploaded_file etc. to upload files.

 

refer : http://www.w3schools...file_upload.asp


Thanks & Regards,
PravinS | Blog


#7 p0werdirector

p0werdirector

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 10 May 2013 - 02:40 AM

Doesnt that just store it on the webserver? it needs to be stored on a seperate server



#8 PravinS

PravinS

    Advanced Member

  • Members
  • PipPipPip
  • 431 posts
  • LocationNashik, India

Posted 10 May 2013 - 03:50 AM

So you can use FTP php script. Just create single FTP account and use your above code for uploading, but do take security measures.


Thanks & Regards,
PravinS | Blog


#9 p0werdirector

p0werdirector

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 10 May 2013 - 04:00 AM

I tried that and the code works now. but it leads me to /ftp.php. apparently i dont have this file on my server and i dont know what this file is good for and what it does.



#10 Irate

Irate

    Advanced Member

  • Members
  • PipPipPip
  • 358 posts
  • LocationHamburg, Germany
  • Age:17

Posted 10 May 2013 - 04:37 AM

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="">
Quod placet mihi non placeat tibi. - What I think to be good must not always equal your perception of it.

I am not perfect. I try a lot with the code I provide and I don't guarantee for it to work as I have mostly no option to test it on my mobile phone. I do apologize for any inconvenience I caused, but if I do happen to have helped, liking my posts or marking them as to have solved or answered your question would be nice.

#11 p0werdirector

p0werdirector

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 10 May 2013 - 04:44 AM

Alright, the files are created and it now leads me to 
Fatal error: Call to undefined function ftp_connect() in /home/virtual/test-mediaz.eu/htdocs/ftp.php on line 8
FTP is installed on the server

Edited by p0werdirector, 10 May 2013 - 04:47 AM.


#12 Irate

Irate

    Advanced Member

  • Members
  • PipPipPip
  • 358 posts
  • LocationHamburg, Germany
  • Age:17

Posted 10 May 2013 - 04:47 AM

Strange, ftp_connect() is a function since PHP 4 :/

What PHP version is your server using?
Quod placet mihi non placeat tibi. - What I think to be good must not always equal your perception of it.

I am not perfect. I try a lot with the code I provide and I don't guarantee for it to work as I have mostly no option to test it on my mobile phone. I do apologize for any inconvenience I caused, but if I do happen to have helped, liking my posts or marking them as to have solved or answered your question would be nice.

#13 p0werdirector

p0werdirector

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 10 May 2013 - 04:51 AM

I dont know which exact version its using since i am not the administrator and i cant contact him at the moment. The only thing i can say is that its a LiteSpeed Web Server



#14 PravinS

PravinS

    Advanced Member

  • Members
  • PipPipPip
  • 431 posts
  • LocationNashik, India

Posted 10 May 2013 - 05:21 AM

Please check the server configuration and also check that FTP functions are enabled on web server


Thanks & Regards,
PravinS | Blog





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com