Jump to content

Accessing uploaded file data


Karaethon

Recommended Posts

I am trying to write a phone script that will accept a file uploaded by a user, read and alter the file byte by byte then return the file to the user. The class that alters the file I have already written but I don't know how to accept the uploaded file data, how to read it byte by byte, what to do with the altered data until the file alteration is complete, and how to return it to the user. Any help would be greatly appreciated.

Link to comment
Share on other sites

The real problem is I don't know what the uploaded data looks like on the server side, I don't know what commands PHP has to allow me to read the file data so I can alter it, and I don't know how to store/compile the altered data until I return it to the user. Since I don't know this stuff I can't figure out how to write an interface between the user and the class that alters the data.

Link to comment
Share on other sites

What kind of data are you expecting to work with? PHP can work with image, text, JSON, XML, PDF, and many other types of data but it's all done differently. So, what are you actually trying to accomplish other than altering user-supplied data?

Link to comment
Share on other sites

I think I'm going to take the surprisingly unpopular standpoint that you know more about what you're working with than we do, so

1 hour ago, Karaethon said:

I don't know how to accept the uploaded file data, how to read it byte by byte, what to do with the altered data until the file alteration is complete, and how to return it to the user.

Accept the file upload using the normal method. PHP will create a temporary file on the server which you can read using functions like fopen, fread, and fclose. Kind of an open question about exactly how you intend to "alter" the data... You can return it to the user with a download prompt:

header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=" . $filename);
/* output file here */
exit;

 

Link to comment
Share on other sites

Ok. Maxxd, I will accept any file type the user submits, the alteration is an encryption algorithm based upon a multi-step pivoting value and a continuouly morphing key, so any file the user supplies (within size limits set by PHP/server) will be accepted and altered.

 

Requinix, thank you for pointing me in the (hopefully) right direction.

Link to comment
Share on other sites

38 minutes ago, Karaethon said:

the alteration is an encryption algorithm based upon a multi-step pivoting value and a continuouly morphing key, so any file the user supplies (within size limits set by PHP/server) will be accepted and altered.

Block cipher? fopen + fread blocks of whatever size until you reach the end + fclose. If you use the r+ file opening mode then you can read the blocks and write the encrypted output back to it. readfile can output the file (alternatively fseek() to 0 and fpassthru()), and when your script ends PHP will clean up the file for you since you were using the temporary file it had created.

Link to comment
Share on other sites

1 hour ago, benanamen said:

Best I can tell is it is some kind of homemade file encrypter.

Yes, I spent from 2010 to 2016 designing, writing, testing, and attempting to hack a new algorithm that does not rely on prime numbers and that would be resistant to quantum computing's ability to express multiple states at the same time. After being satisfied that it met my requirements I have been polishing the functionality and now I am ready to begin beta testing it so I wanted to put an essential version of it on my site for the beta testers to play with and find anything I might have missed.

Link to comment
Share on other sites

10 minutes ago, Karaethon said:

I wanted to put an essential version of it on my site for the beta testers to play with and find anything I might have missed.

The best way to find out if you "missed" anything is to post your code on a repo for peer review. Based on the questions you have been asking I would personally have to question your ability to write a secure encryption algorithm which is no small task, but then you could be a wizard mathematician for all I know. Best thing is to show us the code.

EDIT: Nothing personal by the way

Link to comment
Share on other sites

No offense taken. I am fluent in some languages, mostly basic variants and such, but I have no experience with PHP so I don't know what it can do or how to do things I know how you feel do in basic. 

 

And I'm not looking for what I missed in the code, I'm looking for what I missed in the design, I tested every way I could think of but I know that doesn't mean I thought of everything so my beta testers will hopefully find anything I missed.

Edit: and yes, mathematics is my playground when I'm bored. I try to solve new unsolvables when I can't find anything to occupy my time.

Link to comment
Share on other sites

2 minutes ago, Karaethon said:

I'm not looking for what I missed in the code

You VERY MUCH should be!

Anyways, I am sure you have learned things in your quest which is always a good thing and you can't knock a guy for trying. You have to start somewhere. By the way, your response a couple posts back was what I was trying to get at when I was asking what you are really doing instead of how you are trying to do it. It is much better for us to know that as the opener so we can properly respond to you.

Link to comment
Share on other sites

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.