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 4003604
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:10:22+00:00 2026-05-20T08:10:22+00:00

I’m having trouble getting file_put_contents() to work in uploading decoded email attachments as files

  • 0

I’m having trouble getting file_put_contents() to work in uploading decoded email attachments as files onto my server. Here is the basic script:

$user = "user";
$pass = "pass";
$host = "ftp://mydomain.com";   

$content = 'hello';
$file = 'public_html/mydomain.com/files/readme.txt';

$options = array('ftp' => array('overwrite' => true));
$stream = stream_context_create($options);

$hostname = $user . ":" . $pass . "@" . $host . "/" . $file; 

file_put_contents($hostname, $content, 0, $stream); 

I’ve tried various formulations of this, including logging in as different ftp users, and no matter what I do I get a “no such file or directory” error. My server has the typical structure of “/public_html/mydomain.com/” file structure, but this doesn’t seem to work.

However, when I try to us ftp_put(), it seems to make the connection and find the directory just fine — but I can’t use ftp_put() because I’m not uploading a local file but a string to a remote file.

Here’s the code I used for that:

$user = "user";
$pass = "pass";
$host = "mydomain.com";   

$ftp_path = '/public_html/files';

$content = 'localfile.txt'

$conn_id = ftp_connect($host, 21) or die ("Cannot connect to host"); 

ftp_pasv($conn_id, true);
ftp_login($conn_id, $user, $pass) or die("Cannot login");
// perform file upload
ftp_chdir($conn_id, '/public_html/mydomain.com/files/');
$upload = ftp_put($conn_id, $ftp_path, $content, FTP_BINARY);
if($upload) { $ftpsucc=1; } else { $ftpsucc=0; }

ftp_close($conn_id); 

I realize that I’m probably missing something dead simple, any help?

  • 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-20T08:10:23+00:00Added an answer on May 20, 2026 at 8:10 am

    You have this line in your code:

    $file = 'public_html/mydomain.com/files/readme.txt';

    Which makes me assume: either your working script is outside Web-root, OR the code is wrong… You sure file’s location is right?

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have thousands of HTML files to process using Groovy/Java and I need to
I have a bunch of posts stored in text files formatted in yaml/textile (from
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.