csckid Posted July 15, 2010 Share Posted July 15, 2010 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 More sharing options...
Fergal Andrews Posted July 15, 2010 Share Posted July 15, 2010 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 Link to comment https://forums.phpfreaks.com/topic/207799-string-into-byte-into-file/#findComment-1086393 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.