Because of limitations of my provider, I am forced to use the ftp
functions to upload files to my server (the permissions on the server
will not allow me to load files via php).
I have successfully ported the sample code from php.net to do everything
BUT upload the file. I can connect. I can log in. I can change
directories. But the file never uploads. As I note in the code, I have
tried using ftp_put with the local filename, and I have tried using
ftp_fput with the file in /tmp/php with no luck. Suggestions are welcome.
David -
---------------------
-
<?php
-
$tmp = $_FILES['loadfile']; // passed in correctly as shown on next line
-
echo "<pre>" . print_r($tmp) . "</pre>";
-
-
$upload_form_file = $tmp['name']; // have tried using the tmp_name
-
element combined with ftp_fput
-
$dest_file = "bob.gif"; // just a name to try
-
-
// set up a connection or die
-
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to
-
$ftp_server"); // works
-
-
// try to login
-
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
-
echo "<p>Connected as $ftp_user@$ftp_server</p>\n"; // this is printed
-
} else {
-
echo "Couldn't connect as $ftp_user\n";
-
}
-
-
echo "<p>Current directory is now: " . ftp_pwd($conn_id) . "</p>\n"; //
-
this gives the root
-
-
if (ftp_chdir($conn_id, $base_path)) {
-
echo "<p>Current directory is now: " . ftp_pwd($conn_id) . "</p>\n";
-
// this prints /the/path/to/docs
-
} else {
-
echo "Couldn't change directory\n";
-
}
-
-
echo "<p>upload_form_file: $upload_form_file <br>\ndest_file: $dest_file
-
</p>\n"; // files are listed
-
-
if (ftp_put($conn_id, $dest_file, $upload_form_file, FTP_BINARY)) {
-
echo "successfully uploaded";
-
} else {
-
echo "There was a problem while uploading $file\n"; // this always
-
triggers
-
}
-
-
// close the connection
-
ftp_close($conn_id);
-
-
?>
-
3 2262
Dude:
Here I am replying to myself on the list so that others won't suffer as
I have. I finally figured out that ftp_put and ftp_fput are running *on
the server* and so don't know anything about the client's file system.
They are putting files from the php server onto some other remote
server. Therefore, the only file they are going to know about is the
temp file that php creates on the fly. Once I changed my code to use the
php tmp file, the upload worked smoothly.
HTH,
David
David wrote: Because of limitations of my provider, I am forced to use the ftp functions to upload files to my server (the permissions on the server will not allow me to load files via php).
I have successfully ported the sample code from php.net to do everything BUT upload the file. I can connect. I can log in. I can change directories. But the file never uploads. As I note in the code, I have tried using ftp_put with the local filename, and I have tried using ftp_fput with the file in /tmp/php with no luck. Suggestions are welcome.
David
- ---------------------
- <?php
- $tmp = $_FILES['loadfile']; // passed in correctly as shown on next line
- echo "<pre>" . print_r($tmp) . "</pre>";
- $upload_form_file = $tmp['name']; // have tried using the tmp_name
- element combined with ftp_fput
- $dest_file = "bob.gif"; // just a name to try
- // set up a connection or die
- $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to
- $ftp_server"); // works
- // try to login
- if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
- echo "<p>Connected as $ftp_user@$ftp_server</p>\n"; // this is printed
- } else {
- echo "Couldn't connect as $ftp_user\n";
- }
- echo "<p>Current directory is now: " . ftp_pwd($conn_id) . "</p>\n"; //
- this gives the root
- if (ftp_chdir($conn_id, $base_path)) {
- echo "<p>Current directory is now: " . ftp_pwd($conn_id) . "</p>\n";
- // this prints /the/path/to/docs
- } else {
- echo "Couldn't change directory\n";
- }
- echo "<p>upload_form_file: $upload_form_file <br>\ndest_file: $dest_file
- </p>\n"; // files are listed
- if (ftp_put($conn_id, $dest_file, $upload_form_file, FTP_BINARY)) {
- echo "successfully uploaded";
- } else {
- echo "There was a problem while uploading $file\n"; // this always
- triggers
- }
- // close the connection
- ftp_close($conn_id);
- ?>
-
David wrote: Because of limitations of my provider, I am forced to use the ftp functions to upload files to my server (the permissions on the server will not allow me to load files via php).
I have successfully ported the sample code from php.net to do everything BUT upload the file. I can connect. I can log in. I can change directories. But the file never uploads. As I note in the code, I have tried using ftp_put with the local filename, and I have tried using ftp_fput with the file in /tmp/php with no luck. Suggestions are welcome.
David
- ---------------------
- <?php
- $tmp = $_FILES['loadfile']; // passed in correctly as shown on next line
- echo "<pre>" . print_r($tmp) . "</pre>";
- $upload_form_file = $tmp['name']; // have tried using the tmp_name
- element combined with ftp_fput
- $dest_file = "bob.gif"; // just a name to try
- // set up a connection or die
- $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to
- $ftp_server"); // works
- // try to login
- if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
- echo "<p>Connected as $ftp_user@$ftp_server</p>\n"; // this is printed
- } else {
- echo "Couldn't connect as $ftp_user\n";
- }
- echo "<p>Current directory is now: " . ftp_pwd($conn_id) . "</p>\n"; //
- this gives the root
- if (ftp_chdir($conn_id, $base_path)) {
- echo "<p>Current directory is now: " . ftp_pwd($conn_id) . "</p>\n";
- // this prints /the/path/to/docs
- } else {
- echo "Couldn't change directory\n";
- }
- echo "<p>upload_form_file: $upload_form_file <br>\ndest_file: $dest_file
- </p>\n"; // files are listed
- if (ftp_put($conn_id, $dest_file, $upload_form_file, FTP_BINARY)) {
- echo "successfully uploaded";
- } else {
- echo "There was a problem while uploading $file\n"; // this always
- triggers
- }
- // close the connection
- ftp_close($conn_id);
- ?>
-
You will definitely have to use tmp_name.
Are you sure the user you're connecting with has the ability to upload files to
the specified directory? If you're not absolutely sure, try it manually with
your ftp program.
Also, you might want to put error_reporting(E_ALL); at the top of your script.
Regards,
Shawn
--
Shawn Wilson sh***@glassgiant.com http://www.glassgiant.com
David wrote: Because of limitations of my provider, I am forced to use the ftp functions to upload files to my server (the permissions on the server will not allow me to load files via php).
I have successfully ported the sample code from php.net to do everything BUT upload the file. I can connect. I can log in. I can change directories. But the file never uploads. As I note in the code, I have tried using ftp_put with the local filename, and I have tried using ftp_fput with the file in /tmp/php with no luck. Suggestions are welcome.
David
- ---------------------
- <?php
- $tmp = $_FILES['loadfile']; // passed in correctly as shown on next line
- echo "<pre>" . print_r($tmp) . "</pre>";
- $upload_form_file = $tmp['name']; // have tried using the tmp_name
- element combined with ftp_fput
- $dest_file = "bob.gif"; // just a name to try
- // set up a connection or die
- $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to
- $ftp_server"); // works
- // try to login
- if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
- echo "<p>Connected as $ftp_user@$ftp_server</p>\n"; // this is printed
- } else {
- echo "Couldn't connect as $ftp_user\n";
- }
- echo "<p>Current directory is now: " . ftp_pwd($conn_id) . "</p>\n"; //
- this gives the root
- if (ftp_chdir($conn_id, $base_path)) {
- echo "<p>Current directory is now: " . ftp_pwd($conn_id) . "</p>\n";
- // this prints /the/path/to/docs
- } else {
- echo "Couldn't change directory\n";
- }
- echo "<p>upload_form_file: $upload_form_file <br>\ndest_file: $dest_file
- </p>\n"; // files are listed
- if (ftp_put($conn_id, $dest_file, $upload_form_file, FTP_BINARY)) {
- echo "successfully uploaded";
- } else {
- echo "There was a problem while uploading $file\n"; // this always
- triggers
- }
- // close the connection
- ftp_close($conn_id);
- ?>
-
You will definitely have to use tmp_name.
Are you sure the user you're connecting with has the ability to upload files to
the specified directory? If you're not absolutely sure, try it manually with
your ftp program.
Also, you might want to put error_reporting(E_ALL); at the top of your script.
Regards,
Shawn
--
Shawn Wilson sh***@glassgiant.com http://www.glassgiant.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Tim218 |
last post by:
Hi Everyone
This is my first day with PHP and, not surprisingly, I've run into a problem
:-)
I want to allow file uploads to the server without exposing the
non-technical end-users to FTP...
|
by: OneSolution |
last post by:
Hi All,
Here's one thing that I don't know much about - file uploading. As part of
my project, I will have to build a file manager of sorts - perhaps a
document manager. Anyhow, this involves...
|
by: Dino |
last post by:
dear all,
i've created an application for a customer where the customer can upload
..csv-files into a specified ftp-directory. on the server, a php-script,
triggered by a cronjob, reads all the...
|
by: Sky Sigal |
last post by:
I have created an IHttpHandler that waits for uploads as attachments for a
webmail interface, and saves it to a directory that is defined in
config.xml.
My question is the following:
assuming...
|
by: Nexus |
last post by:
I have created a program in Visual Basic that creates CSV file on the PC.
However I need to do an upload of these files into DB2 tables (from time to
time)
I'm currently using ADO to create a...
|
by: Ashok |
last post by:
Dear Friends,
How to download a file from server to client local pc without user
intervention ie without the save as popup window.
Can you give me step by step.
Thanks
|
by: fReDiNi |
last post by:
Hi, I have being trying fo find the best solution for this problem for
2 days now and I am not able to find a solution.I need help.
I explain the problem:
A customer needs a system so that...
|
by: Bonzol |
last post by:
Vb.net 2003, Web application
Hey all!
Just a quick question.
I have a site which allows users the ability to upload files by the
HTML brows button control.
My question is if a user submits...
|
by: KevinADC |
last post by:
Note: You may skip to the end of the article if all you want is the perl code.
Introduction
Many websites have a form or a link you can use to download a file. You click a form button or click...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |