I upload the rsa private key (.pem file) to my site and use fopen to read the content, but lately I keep repeating the same error all the time, without much sense.
HTML
<form enctype="multipart/form-data" action="upload.php" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="1000000" /> Choose a file to upload: <input name="uploaded_file" type="file" /> <input type="submit" value="Upload" /> </form>
upload.php
<?php session_start(); if( $_SERVER['SERVER_PORT'] == 80) { header('Location:https://'.$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"]); die(); } echo $_FILES['uploaded_file']['name']; //heck that we have a file if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) { $filename = basename($_FILES['uploaded_file']['name']); $ext = substr($filename, strrpos($filename, '.') + 1); if (($ext == "pem") && ($_FILES["uploaded_file"]["type"] == "text/plain")) { $fh = fopen($_FILES['uploaded_file']['name'], 'r'); //continue with code } else { echo "Error: Only pem files are accepted for upload"; } } else { echo "Error: No file uploaded"; } ?>
The site continues to return an error:
Warning: fopen (mykey.pem) [function.fopen]: could not open stream: there is no such file or directory in .... on line 38
(this is the fopen line). The fact that it falls into the fopen state proves that it actually loads, but uses fopen (also tried using file_get_contents ($ _ FILES ['uploaded_file'] ['name']), and also unsuccessfully) returns an error.
what a fluff!
FINAL NOTES:
For some reason, fopen () does not like to read OpenSSL certificates and returns eror:
openssl_private_decrypt (): supplied resource is not valid OpenSSL X.509 / key resource
if you use file_get_contents, it works.
source share