Can i use php ftp?

No longer supported!

Moderator: Moderators

Postby tharix » Fri Jun 18, 2004 6:41 pm

Can I use php ftp (i mean the php ftp functions) to upload files??
My script should work.. but the error said he couln't connect while the login-data is correct...

oh, this script comes from a webpage that I'm building for somebody else...

the script:


if(!isset($upload)) {
$upload = "";
}
switch($upload) {
default:
include "config.php";
?>
<form name="file" method=POST action="ftpupload.php?upload=doupload" enctype="multipart/form-data">

<input type=hidden name=type value="">


Plaatje:<br>
<input type=file name=source_file size=20> <br>
     
<input type=submit name=btnSubmit value=Submit size=20></form>

<?php
break;
case "doupload":

$ftp_server='ftp.polarhome.com';//serverip
$conn_id = ftp_connect($ftp_server,791);


// login with username and password
$user="mierlo";
$passwd="*****";
$login_result = ftp_login($conn_id, $user, $passwd);

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

//directorylike /www.velibaba.com/images
ftp_pasv($conn_id,TRUE);
ftp_chdir($conn_id,'/public_html/upload');

//$destination_file=ftp_pwd($conn_id);

$destination_file=$_FILES['file']['name'];
echo ("<br>");
print $destination_file;

echo ("<br>");

if($_FILES['file']['type']== "image/pjepg" || $_FILES['file']['type']== "image/gif"){
if($_FILES['file']['size']< "800000"){
// 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";
print"
De url die je kunt gebruiken om het plaatje te includen is:<br>
<em><img src='http://www.polarhome.com/~mierlo/upload/$destination_file'></em><br>
<br>
Het plaatje dat je uploade:<br>
<img src='http://www.polarhome.com/~mierlo/upload/$destination_file'><br><br>
<br><a href='Javascript: history.go(-1)'>Upload opnieuw een plaatje!</a><br>
";
}
}else{
print"Verkeerd type bestand! Ga terug met de knop terug/back!";
}
}else{
print"Het bestand is te groot! Ga terug met de knop terug/back!";
}
// close the FTP stream
ftp_close($conn_id);
}


//======================================================================

break;
}

PS Don't mention the dutch text... and my bad english
tharix
 

Postby DenisF » Fri Jun 18, 2004 11:35 pm

If it's inside the polarhome system, why bother with external hostnames and ports?

try redhat.polarhome.com for hostname, and plain ol' port 21 for ftp.
Image
[ FAQ ] :: [ Policy ] :: [ Port Forwarding Guide ] :: [ Search ]
User avatar
DenisF
Forum Admin
Forum Admin
 
Posts: 679
Joined: Mon Dec 16, 2002 9:09 pm
Location: Israhell


Return to FTP accounts

Who is online

Users browsing this forum: No registered users and 3 guests

cron