Save file upload to txt file

Asked

Viewed 60 times

1

I have this code that records the form information in a file TXT. But I can’t upload (an image for example).

How can I do that?

Code:

<?php

$file = 'apeople.txt';

// Open the file to get existing content
$current = file_get_contents($file);

// Append a new person to the file
$current .= $_POST ["top"]; $current .= "\n";
$current .= $_POST ["texto"]; $current .= "\n";
$current .= $_FILES ['arquivo']; $current .= "\n";
$current .= $_POST ["rodape"]; $current .= "\n";

// Write the contents back to the file
file_put_contents($file, $current);

?>
  • The value of $_FILES ['arquivo'] is not what you think it is, make a var_dump from him to see what’s inside

  • I don’t understand what I mean friend, I’m a little layy in php.

  • And how you want to store an image inside a TXT file?

  • Read the documentation: http://php.net/manual/en/features.file-upload.post-method.php

  • No, I want it to be root or in a folder, but your information to be in the file, like this: <img style="width: auto; height: auto;" alt="" src="img.jpg">

1 answer

0


Buddy, I’m sorry, but it’s impossible for you to save an image inside a .txt. What you can do is save the image name inside the txt and play the image in some folder.

The file name would be on

$_FILES ['file'][name]

Your code would look like this:

$current .= $_FILES ['arquivo'][name];
  • Thanks a friend, it worked.

  • Hello @F.Junior ,I see that you have a total of 5 questions so far and although the answers given to you have helped you have never accepted an answer. This is not good for the health of the site, because your question is not solved, accepting an answer will reward those who helped you and help those who have the same problem. = D -- Valley just you take a look at our [Tour]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.