De nuevo gracias por tu ayuda, Cluster.
La ruta que utilizo en el otro script era la absoluta (/home/..../..../), pero me da error de acceso denegado.
Sin embargo, he conseguido subir un archivo a mi servidor utilizando un script para conectar via FTP:
Formulario:
Código PHP:
<html>
<body marginwidth=4 marginheight=4 topmargin=4 leftmargin=4 bgcolor=white vlink="#0000ff" link="#0000ff">
<form name="Attachments" method=POST action="ftp2.php" enctype="multipart/form-data">
<input type=hidden name=box value="">
<tr>
<td nowrap width="1%"> <b>Image:</b></td>
<td colspan=2>
<input type=file name=source_file size=20> <br>
</td>
</tr>
<input type=submit name=btnSubmit value=Submit size=20 style="border: 1px solid #0000FF"></form>
</body>
</html>
ftp2.php:
Código PHP:
<?php
$ftp_server='ftp.tuservidor.com';//serverip
$conn_id = ftp_connect($ftp_server);
// login with username and password
$user="usuario_ftp";
$passwd="clave_ftp";
$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_chdir($conn_id, "httpdocs");
ftp_chdir($conn_id, "mi_carpeta");
//$destination_file=ftp_pwd($conn_id);
$destination_file="x.jpg";
echo ("<br>");
print $destination_file;
echo ("<br>");
// 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";
}
// close the FTP stream
ftp_close($conn_id);
?>
Script obtenido en
www.php.net:
-
Funciones FTP
-
ftp_put()
¿Qué os parece?