
May 15th, 2003, 11:18 AM
|
|
Junior Member
|
|
Join Date: Mar 2003
Posts: 11
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Uploading files with FTP (resolved)
I've been having a bit of trouble getting my FTP upload script working on my site..
Here it is, I guess my real trouble is getting it to upload to a certain folder..
I've gotten several errors with slight variations in the script:
'STOR' not understood, folder does not exist (it tries to make some tmp folders), and something about the folder not being a file.
PHP Code:
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
ftp_chdir($conn_id, "/");
ftp_chdir($conn_id, "files");
$destination_file=ftp_pwd($conn_id);
$upload = ftp_put($conn_id, $destination, $datafile, FTP_BINARY);
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination";
}
ftp_close($conn_id);
Nevermind, I figured something out (and it works like a charm).
PHP Code:
<?php
$ftp_server = "ftp.yoursite.com";
$ftp_user_name = "yourusername";
$ftp_user_pass = "yourpassword";
if ($Submit){
if ($img1_name != "") {
@copy("$img1" , "../files/$img1_name")
or die("Couldn't Upload Your File.");
}
else
{
die("No File Specified");
}
echo "<font size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\"><strong>File Upload Successful</strong>
<P>Successfully Uploaded: $img1_name ($img1_size bytes) </P></font><META HTTP-EQUIV=\"refresh\" content=\"1;URL=index.php?s=uploadfiles\">";
}
else
{
?>
<FORM ACTION="index.php?s=uploadfiles" METHOD="POST" ENCTYPE="multipart/form-data">
<P>
<CENTER>
<P>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="36%" HEIGHT="80">
<TR>
<TD HEIGHT="20" COLSPAN="3"> </TD>
</TR>
<TR>
<TD HEIGHT="20" COLSPAN="3">
<P ALIGN="CENTER"><B><FONT size="1" FACE="Verdana">Upload A File</FONT></B>
</TD>
</TR>
<TR>
<TD WIDTH="6%" HEIGHT="67"> </TD>
<TD WIDTH="88%" HEIGHT="67">
<P ALIGN="CENTER"> <INPUT TYPE="file" NAME="img1" SIZE="30" style="color:#000000; background: #CCCCCC; border:000000; height:17;">
</TD>
<TD WIDTH="6%" HEIGHT="44"> </TD>
</TR>
<TR>
<TD HEIGHT="54" COLSPAN="3">
<CENTER>
<P><INPUT TYPE="SUBMIT" NAME="Submit" VALUE="Upload File" style="color:#000000; background: #CCCCCC; border:000000; height:17;">
</CENTER>
</TD>
</TR>
<TR>
<TD WIDTH="6%"> </TD>
<TD WIDTH="88%"> </TD>
</TR>
</TABLE>
</CENTER>
<P>
</FORM>
</BODY>
</HTML>
<?php
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
echo "<font size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\"><strong>Contents of Folder:</strong></font>";
$list = array();
$list = ftp_nlist($conn_id, "files/");
$listcount = count($list);
$i = 0;
while ($i < $listcount){
$list[$i]=ereg_replace("files//", "", $list[$i]);
echo "<font size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">
<form action=\"index.php?s=uploadfiles\" method=\"post\">
<input name=\"filename\" type=\"hidden\" value=\"$list[$i]\">"; if (!($list[$i])){ echo "Empty"; } else { echo "<input name=\"delete\" type=\"submit\" value=\"Delete\" style=\"color:#000000; background: #CCCCCC; border:000000; height:17;\">"; }
echo "<a href=files/$list[$i] target=_blank>$list[$i]</a><br>
</form></font>
";
$i++;
}
ftp_close($conn_id);
}
if ($delete)
{
$filename = "files/$filename";
$conn_id = ftp_connect("$ftp_server");
$login_result = ftp_login($conn_id,$ftp_user_name,$ftp_user_pass);
$delete = ftp_delete($conn_id, $filename);
ftp_quit($conn_id);
echo "<META HTTP-EQUIV=\"refresh\" content=\"0;URL=index.php?s=uploadfiles\">";
}
?>
Last edited by KaiMunk : May 15th, 2003 at 03:36 PM.
|