View Single Post
Old 03-24-2005, 01:05 PM   #1 (permalink)
pixelbend
Too hot in the hot tub!
 
pixelbend's Avatar
 
[php]FTP upload script

Hi all,

I am writing an FTP upload script and I'm having a weird problem. I wrote it and tested it by uploading the html and php files that make up the script. It will transfer either of those fine, but any other file I try errors out. Heres the code:

Code:
<?php

	//Magna-Tel FTP Upload site
	
	//get variables from form
	$cust = $_POST["customer"];
	$name = $_POST["name"];
	$email = $_POST["email"];
	$ponum = $_POST["ponum"];
	$file = $_POST["file"];
	
	$dest_file = $ponum . "_" . $file;
	
	//Check to see all input is present
	if ($cust == "") echo "<p>Customer name missing!";
	else if($name == "") echo "<p>Name missing!";
	else if($email == "") echo "<p>Email missing!";
	else if($file == "") echo "<p>File name missing!";
	
	//Connect to ftp server
	$ftp_server = "pop3.magna-tel.net";
	$ftp_user_name = "ftpuser";
	$ftp_user_pass = "upload";
	
	$conn_id = ftp_connect($ftp_server);
	$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
	
	// check connection
	if ((!$conn_id) || (!$login_result)) {
		echo "<p>FTP connection has failed!";
		echo "<p>Attempted to connect to $ftp_server for user $ftp_user_name";
		exit;
	}
	else {
		echo "<p>Connected to $ftp_server, for user $ftp_user_name";
	}
	
	// upload the file
	$upload = ftp_put($conn_id, $dest_file, $file, FTP_BINARY);

	// check upload status
	if (!$upload) {
		echo "<p>FTP upload has failed!";
	}
	else {
		echo "<p>Uploaded $file to $ftp_server as $dest_file";
	}

	// close the FTP stream
	ftp_close($conn_id);
	
	//Email art@magna-tel.net and customer with notice
	$art_email = "art@magna-tel.net";
	$art_subject = "FTP file has been uploaded";
	$art_body = "$name from $cust has uploaded file $file to the FTP server.\nPlease check as soon as possible.";
	$art_return = "From:davidg@magna-tel.net";
	
	if ($upload) mail ($art_email, $art_subject, $art_body, $art_return);

?>
I get the "FTP upload has failed!" on all files except upload.php and upload.html
__________________
But I don't want ANY Spam!
pixelbend is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73