Log in

View Full Version : Upload file via FTP



pavmoxo
05-31-2006, 11:31 AM
Itīs possible upload a file in PHP via FTP??

gold2040
05-31-2006, 11:45 AM
If you mean is it possible to upload a file with a .php extension then yes it is

pavmoxo
05-31-2006, 11:51 AM
I'm sorry I don´t mean that!!

But upload a file with .pdf or .jpg extension for a DB when you have a field with the type file

Twey
05-31-2006, 12:07 PM
You wish to use PHP to upload a file to a server via FTP?
You can do this. Have a look at http://www.php.net/ftp

gold2040
05-31-2006, 02:56 PM
oops....must have miss interpreted your question paramoxo :D

moscarda
06-08-2006, 02:53 PM
You wish to use PHP to upload a file to a server via FTP?
You can do this. Have a look at http://www.php.net/ftp

wow thanks for the link, i've been looking for the same thing a while

djr33
06-08-2006, 05:24 PM
Note that there are easier ways to do this if its the same server the php is running from. You can open/modify/save files from the local server.
FTP is only needed if you're working with more than one.

pavmoxo
06-20-2006, 06:02 PM
Isn't more safe to do a upload via ftp that via http? Give me some advantages and disadvantages by uploading a file with this form to decide better...

One more question. Can I do an update query for change a file?

Twey
06-20-2006, 06:07 PM
Isn't more safe to do a upload via ftp that via http? Give me some advantages and disadvantages by uploading a file with this form to decide better...There are neither equivalent advantages nor disadvantages to the two methods. FTP is easier to use for a remote server, is all, because HTTP requires you to construct the request by hand in PHP. If you're looking for security, PHP (with appropriate modules and compilation options) can upload a file via SSH, which is encrypted and therefore considerably more secure.
One more question. Can I do an update query for change a file?No, you must download it, edit it, delete the original, then upload your copy in its place.

djr33
06-20-2006, 11:28 PM
Not neccessarily... you can modify files that are on the server through php, but it is hard to do so, depending on complexity. You'd never want to do more than a text file like that.
Now... it wouldn't be updating... it would be creating a new one and replacing, but all in PHP.

Twey
06-21-2006, 06:02 AM
Not neccessarily... you can modify files that are on the server through php, but it is hard to do so, depending on complexity.Not via FTP, you can't. :)

pavmoxo
06-21-2006, 09:17 AM
Someone tell me that with ftp continues upload a file to the end despite network problems and with http the upload breaks. Itīs true??


One more question. Can I do an update query for change a file?

The question isn't completely right. I will reformulate:

Can I do an update query via ftp?

pavmoxo
06-21-2006, 10:56 AM
I don´t understand why doesn't update the register knowing that with a insert query works:



if ($_POST["edit"] == "Alterar")
{
if ($_POST["titulo"] != "")
{
// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// check connection
if ((!$conn_id) || (!$login_result)) {
//echo "FTP connection has failed!";
echo "<script>alert('Liga&#231;&#227;o ao servidor FTP falhada.');</script>";
//echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
//echo "Connected to $ftp_server, for user $ftp_user_name";
}


// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);

// check upload status
if (!$upload) {
$sql = "update livros set imagem = '', titulo = '".$_POST["titulo"]."', autor = '".$_POST["autor"]."', ano = '".$_POST["ano"]."', editora = '".$_POST["editora"]."', link = '".$_POST["link"]."', link_text = '".$_POST["link_text"]."', descricao = '".$_POST["descricao"]."', cat_ID = '".$_POST["cat_ID"]."' where livro_ID = ".$_POST["livro_ID"];
echo "<script>alert('Ficheiro actualizado com sucesso sem imagem.');</script>";
} else {
if (is_file("../images/livros/".$_FILES['file']['name'])) {
$sql = "update livros set imagem = 'images/livros/".$_FILES["file"]["name"]."', titulo = '".$_POST["titulo"]."', autor = '".$_POST["autor"]."', ano = '".$_POST["ano"]."', editora = '".$_POST["editora"]."', link = '".$_POST["link"]."', link_text = '".$_POST["link_text"]."', descricao = '".$_POST["descricao"]."', cat_ID = '".$_POST["cat_ID"]."' where livro_ID = ".$_POST["livro_ID"];
//echo " Actual query: " .$sql;
echo "<script>alert('Ficheiro actualizado com sucesso.');</script>";
}
//echo "Uploaded $source_file to $ftp_server as $destination_file";
}

// close the FTP stream
ftp_close($conn_id);
}
else
{
echo "<script>alert('T&#237;tulo obrigat&#243;rio.');</script>";
}
}


Can you explain??

NOTE: it confirms the updating but the register don&#180;t modify!!