Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6157969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:52:29+00:00 2026-05-23T20:52:29+00:00

Once again I need some much appreciated help from the experts :) I am

  • 0

Once again I need some much appreciated help from the experts 🙂
I am trying to use PHP’s FTP functions to upload a file to the server via a web form, I’ve spent the day Googling for a simple tutorial but most seem to expect a certain level of understanding about the process. So, I’ve found an example that I believe will do the job for me, but I frankly don’t understand how to concoct the ftp path?

Here’s the script in it’s entirety (I found it on Tech Republic)

<?
// get FTP accessparameters
$host = "<URL of site>";
$user = "user@<URL of site>";
$pass = "<PASSWORD>";
$destDir= "www/uploads/files/";
$workDir= "/usr/local/temp"; // define this as perlocal system
// get temporary file namefor the uploaded file
$tmpName= basename($_FILES['ufile']['tmp_name']);
// copy uploaded file intocurrent directory
move_uploaded_file($_FILES['ufile']['tmp_name'], $workDir."/".$tmpName) or die("Cannot move uploaded file toworking directory");
// open connection
$conn= ftp_connect($host) or die ("Cannot initiate connection tohost");
// send access parameters
ftp_login($conn,$user, $pass) or die("Cannot login");
// perform file upload
$upload = ftp_put($conn, $destDir."/".$_FILES['ufile']['name'], $workDir."/".$tmpName, FTP_BINARY);
// check upload status
// display message
if (!$upload) {
    echo "Cannotupload";
} else {
    echo "Uploadcomplete";
}
// close the FTP stream
ftp_close($conn);
// delete local copy ofuploaded file
unlink($workDir."/".$tmpName) or die("Cannot delete uploaded filefrom working directory -- manual deletion recommended");
?>

At the moment it’s failing with “Cannot move uploaded file to working directory” – so I am assuming that the path is incorrect.
When this particular user connects via ftp, their home directory is “files”.

I appreciate the advice.

Answer below

I have it working.
Because the users home directory is “files” it required that inside this directory there be two further directories called “file” and “temp”
I altered the code above to:-

$destDir= "files";
$workDir= "temp";

and found an example of an ftp connection string to work backwards from so that the code generated the correct format.
Easy when you know how!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:52:30+00:00Added an answer on May 23, 2026 at 8:52 pm

    I have it working. Because the users home directory is “files” it required that inside this directory there be two further directories called “file” and “temp” I altered the code above to:-

    $destDir= "files";
    $workDir= "temp";
    

    and found an example of an ftp connection string to work backwards from so that the code generated the correct format. Easy when you know how!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Once again I need some help. I'm creating a multiple file upload function with
Once again, I need some help and I appreciate you all for being here
Once again I need some help. I'm working with a table that contains 3
Once again I need your Help, am thanking you as every time you helped
I received some great help here the other day and hope once again I
I am once again looking for some help. I have found this stopwords script
Once again I find myself failing at some really simple task in C++. Sometimes
I need some help with a query (sorry, I'm not too good at this!)
I am working on a small project and I need some help. I have
Im working on a a sudoku program for python and i need some help.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.