Jump to content

string into byte into file


csckid

Recommended Posts

I'm trying to transfer a file using post method. If I write echo $_POST['myfile'] it outputs [b@d590dbc  .  So my server side is obtaining the file. Now I need to convert this peculiar string into file. How do I do that? It was an image file.

$name = trim($_POST["name"]).".png";

$salary=trim($_POST["salary"]);


file_put_contents($name, ($_POST['myfile']));
echo $_POST['myfile'];
//tried both ways
move_uploaded_file(($_POST['myfile']), $name)

Link to comment
https://forums.phpfreaks.com/topic/207799-string-into-byte-into-file/
Share on other sites

Hi csckid,

You use the $_FILES array to access uploaded files. When a file is uploaded it is written to a temporary directory. You then need to move it to its correct location. You access the file using $_FILES['myfile'] , where 'myfile' is the name you gave the file field in your form:

 

$tempName = $_FILES['myfile']['tmp_name'];
$uploadedFilename = $_FILES['myfile']['name'];
$directory = '/uploadedFiles';
move_uploaded_file($tempName, $directory . '/' . $uploadedFilename);

 

Do a var_dump of $_FILES['myfile'] to see all the array variables you can access.

all the best,

Fergal

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.