I have tried files upload to server using ftp connection in php and its not working, its connecting but getting Error like "Connected to XXXXXXXXXXX, for user XXXXXXXXXXXXX FTP upload has failed!"
I have tried following code please help by correcting it,..
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Welcome</title>
</head>
<body>
<form action="upload.php" enctype="multipart/form-data" method="post">
<input name="file" type="file" />
<input name="submit" type="submit" value="Upload File" />
</form>
</body>
</html>
upload.php
<?php
$ftp_server = "XXXX";
$ftp_user_name = "XXXXX";
$ftp_user_pass = "XXXXXXXXXX";
$destination_file = "./imagetest/123/";
$source_file = $_FILES['file']['tmp_name'];
// set up basic connection
$conn_id = ftp_connect($ftp_server);
ftp_pasv($conn_id, true);
// 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 "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) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
// close the FTP stream
ftp_close($conn_id);
?>
You have to add filename after path.
Replace below code and try,
$destination_file = "./imagetest/123/".$_FILES['file']['name'];
$destination_file is not a file it is a directory.
Also you need to change directory to upload file.
Eg.
<?php
ftp_chdir($conn, $destination_directory);
ftp_put($conn, $filename , $source_file, FTP_BINARY );
?>
Related
If I try to upload an image... It shows me the root folder with the size but it shows me only a white square... Not the picture with the resolution...
upload.php
<?php require '../conx.php';
session_start();
if(isset($_SESSION["userID"])){
} else{
header('Location: ../login.php');
}
?>
<?php
$ftp_server = "ftp.xxxx.com";
$ftp_user_name = "xxxx#exemple.com";
$ftp_user_pass = "xxxxx";
$destination_file = "/public_html/lifestyle/imagini/" . $_FILES['file']['name'];
$source_file = $_FILES['file']['tmp_name'];
// set up basic connection
$conn_id = ftp_connect($ftp_server);
ftp_pasv($conn_id, true);
// 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 "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
if (ftp_put($conn_id, $destination_file, $source_file, FTP_ASCII)) {
echo "successfully uploaded $destination_file\n";
header('Location: administrator/admin_index_lifestyle.php');
} else {
echo "There was a problem while uploading $destination_file\n";
}
// close the FTP stream
ftp_close($conn_id);
?>
form
<form action="upload.php" enctype="multipart/form-data" method="post">
<input name="file" type="file" />
Upload foto in folderul lifestyle/imagini/ pentru ARTICOL
<input name="submit" type="submit" value="Upload File in lifestyle" />
</form>
If I try to see the picture using the absolute link, it shows me only a white square... not the image. If I use FtpZilla to upload the image it works...
So there must be a problem in my form.
Once I had the same issue. Solved by adding this attribute to <input type="file">:
accept="image/jpeg"
You can add some more types if you wish. Hope that helps
so i'm trying to make a ftp php uploader on my localhost setup with xampp.
It works fine to upload files from C:\xampp\htdocs\ but if I try to upload a file from my desktop it wont work. is there a way to get the path of the "source" file so I can upload from other places than ...\htdocs\ or how can I fix this?
Files are uploaded to a ftp folder on my desktop, and as I said that works fine when you chose a file from C:\xampp\htdocs.
<?php
if($_POST){
$source = basename($_FILES["source"]["name"]);
$fileType = pathinfo($source, PATHINFO_EXTENSION);
$remote_file = $source;
$ftp_server = '127.0.0.1';
$ftp_user_name = 'xxx';
$ftp_user_pass = 'xxx';
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
if (ftp_put($conn_id, $remote_file, $source, FTP_ASCII)) {
echo "successfully uploaded $source\n";
} else {
echo "There was a problem while uploading $source\n";
}
ftp_close($conn_id);
}
?>
<!DOCTYPE html>
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" id="source" name="source"></input><br>
<input type="submit" value="Upload file" name="submit" id="submit"></input><br>
</form>
</body>
</html>
Your using the name. To access the file that was uploaded you need to use tmp_name. Change $source = basename($_FILES["source"]["name"]); to $source = basename($_FILES["source"]["tmp_name"]);
I am doing image gallery for website but admin want to upload image by him self, so i have prepared this code to transfer images from website to FTP.
But some of them are telling you have to store images path in database then you have to take it from mysql and display / delete / upload images on website.
Since i am new bee in PHP i am not able to do that, so any one can help me with this issue ,... Thanx in advance
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Welcome</title>
</head>
<body>
<form action="upload.php" enctype="multipart/form-data" method="post">
<input name="file" type="file" /><br><br>
<input name="file1" type="file" /><br><br>
<input name="file2" type="file" /><br><br>
<input name="submit" type="submit" value="Upload File" />
</form>
</body>
</html>
upload.php
<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
$ftp_server = "xxxxxxxxxxxxxx";
$ftp_user_name = "xxxxxxxxxxx";
$ftp_user_pass = "xxxxxxxxx";
$folder = "/www/imagetest/123/";
$source_file = $_FILES['file']['tmp_name'];
$source_file1 = $_FILES['file1']['tmp_name'];
$source_file2 = $_FILES['file2']['tmp_name'];
$destination_file = $folder . $_FILES['file']['name'];
$destination_file1 = $folder . $_FILES['file1']['name'];
$destination_file2 = $folder . $_FILES['file2']['name'];
// set up basic connection
$conn_id = ftp_connect($ftp_server);
ftp_pasv($conn_id, true);
// 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 "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);
$upload1 = ftp_put($conn_id, $destination_file1, $source_file1, FTP_BINARY);
$upload2 = ftp_put($conn_id, $destination_file2, $source_file2, FTP_BINARY);
// check upload status
if (!$upload) {
echo "FTP upload 1 has failed!\n";
} else {
echo "1 Uploaded $source_file to $ftp_server as $destination_file\n";
}
if (!$upload1) {
echo "FTP upload 2 has failed!\n";
} else {
echo "2 Uploaded $source_file to $ftp_server as $destination_file\n";
}
if (!$upload2) {
echo "FTP upload 3 has failed!\n";
} else {
echo "3 Uploaded $source_file to $ftp_server as $destination_file\n";
}
// close the FTP stream
ftp_close($conn_id);
?>
This question already has an answer here:
PHP Warning: ftp_fput(): Can't open that file: Is a directory in
(1 answer)
Closed 2 years ago.
I have solved my original question below. What is the best method if I need to insert a progress bar for the file uploader? Using the ftp_put method, doesn't allow to get a response from the server until the file is successfully uploaded.
Thanks!
I'm trying to upload a file using ftp_put and for some reason when I run the code through localhost, it gives me the below error:
Warning: ftp_put(): Can't open that file: Is a directory in C:\xampp\htdocs\ftp\upload_file.php on line 25
<form action="upload_file.php" enctype="multipart/form-data" method="post">
<input name="uploadedfile" type="file" />
<input name="submit" type="submit" value="Upload File" />
</form>
PHP Code:
<?php
$ftp_server = "";
$ftp_user_name = "";
$ftp_user_pass = "";
$destination_file = "/public_html/testing/";
$source_file = $_FILES['uploadedfile']['tmp_name'];
// set up basic connection
$conn_id = ftp_connect($ftp_server);
ftp_pasv($conn_id, true);
// 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 "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) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
// close the FTP stream
ftp_close($conn_id);
?>
Thank you.
Please test chdir that destination or look at this on php.net
Got this cryptic error
Warning: ftp_put() [function.ftp-put]: 'STOR' not understood in
C:\wamp\www\kevtest\ftp_todays.php on line 48
Found the prob, you can't put a path to the destination file
(even though I can do that in the dos ftp client...?)
e.g. - this doesn't work
ftp_put($conn, '/www/site/file.html','c:/wamp/www/site/file.html',FTP_BINARY);
you have to put
<?php
ftp_chdir($conn, '/www/site/');
ftp_put($conn,'file.html', 'c:/wamp/www/site/file.html', FTP_BINARY );
?>
<?php
if(isset($_POST['submit']))
{
ini_set('max_execution_time', 60000);
$file = $_FILES['video']['tmp_name'];
$destination_file = "/public_html/".time().basename($_FILES['video']['name']);
// connect and login to FTP server
$ftp_server = ".com";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, 'name', 'pass');
// upload file
if (ftp_put($ftp_conn, $destination_file, $file, FTP_BINARY))
{ echo "Successfully uploaded ".$_FILES['video']['name']." "; }
else
{ echo "Error uploading $file."; }
// close connection
ftp_close($ftp_conn);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<body>
<div class="container">
<form name="frm" id="frm" method="post" enctype="multipart/form-data">
<div class="input-group">
<input type="file" name="video" required="required" />
</div>
<div class="input-group">
<input type="submit" name="submit" value="Submit" onClick="move()"/>
</div>
</form>
</div>
</body>
</html>
I need to use a form to retrieve text from an online user and create a *.txt file with the submission on my server. I have ftp working now but I could use something else if I have to.
Here's what I've written for the form:
<form name="input" action="upload.php" method="post"
enctype="multipart/form-data">
<textarea input type="text" name="form" cols="100" rows="20"
name="body"></textarea><p>
<input type="submit" name="form" value="Submit"></center>
</form>
Here's my upload.php:
<?php
$filep=$_POST['form']['form'];
$ftp_server=['http://ftp.***.***'];
$ftp_user_name=['***'];
$ftp_user_pass=['***'];
$paths=['***'];
$name=['test.txt'];
$conn_id=ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
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 = ftp_put($conn_id, $paths.'/public_ftp'.$name, $filep, FTP_BINARY);
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $name to $ftp_server ";
}
?>
I starred-out the logon info because it's not necessary.
This script goes blank. Not even an error message.
I'm not even sure if I'm on the right path. I've found bits of code that might work but nothing that does everything I need. Help!