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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:36:23+00:00 2026-05-21T05:36:23+00:00

I am very new to PHP, so forgive me my ignorance. I have HTML

  • 0

I am very new to PHP, so forgive me my ignorance.

I have HTML for for upload:

<form action="upload.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /><br />
<input type="submit" name="submit" value="Submit" />
</form>

My PHP is (It doens’t know, but hopefully it shows what I want):

<?php
if ($_FILES["file"]["error"] > 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "<br />";
  }
else
  {
  $content = fread($_FILES["file"],10);
  echo $content;
  echo "byte10 is: " ???
  }
?>

I want to: From this uploaded file, I want to read a single byte (say byte 10). I want to print out the acscii (HEX) code for this byte. How do I do that? Do I need to save the file to the server?

(The untimate goal is to encrypt the file and send th eencrypted file back to the user. So I want (1) upload file (2) read each individual byte (2) perform encryption on byte level (3) save file and send it back to the user)

  • 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-21T05:36:23+00:00Added an answer on May 21, 2026 at 5:36 am

    Thank you very much for the "ultimate goal" — it will help us make sure that you don’t do something silly by accident.

    Encryption is a very complex topic. You should not write your own encryption routine. Use a complete, pre-built solution.

    Mcrypt is PHP’s best encryption extension. Mcrypt supports multiple common ciphers including AES ("Rijndael"). Encryption is pretty darn easy — use "CBC" mode for your file.


    The Vigenère cipher is a 460-ish year old substitution cipher based on a simple lookup table.

    This explains the whole one-character-at-a-time thing.

    While you can read the whole file one byte at a time, you might find it more convenient to work with a string. You can read the entire file into a variable (through file_get_contents or whatever), and then use substr or the square bracket substring syntax to read the string one byte at a time. Remember, PHP strings are just simple lists of bytes.

    Given $data is the complete data in the file, you can process every byte thusly:

    $length = strlen($data);
    for($i = 0; $i < $length; $i++) {
        $byte = $data[$i];
    // Or
        $byte = substr($data, $i, 1);
    // Process the byte here.
    }
    

    This is only practical for small files (smaller than a few megabytes), as it requires loading the whole file into memory.

    I want to print out the acscii (HEX) code for this byte

    You can get the decimal value using ord, then convert that to a hexadecimal string using dechex:

    $hex_value = dechex(ord($byte));
    

    Post-substitution, you can reverse it — use hexdec to go from hex to decimal, then chr to go from decimal to byte:

    $converted_byte = chr(hexdec($ciphered_hex));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please forgive the ignorance, but I'm very new to PHP and I couldn't find
I am very new to PHP and MySql. Is there any method by which
I'm very new to PHP and I have a small task of displaying a
I'm very new to PHP. I have a line of code on a server
I am very new to PHP, so far I have been using the following
I'm very new to Linux and PHP so forgive me if this is a
Im very new to php and i have a page with 5 includes located
I am very new to php and I have a table that displays cases
I am very new to php, and i have search and put together this
I'm very new to php/SQL (1 day) so forgive me if I am doing

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.