Jump to content
Karaethon

Accessing uploaded file data

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.

Share this post


Link to post
Share on other sites

 Tell tell us about the real problem at hand instead of telling us how you're attempting to solve the real problem.

Share this post


Link to post
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.

Share this post


Link to post
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?

Share this post


Link to post
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;

 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
2 hours ago, Karaethon said:

...to write a phone script that will accept a file uploaded by...

arghh just caught that autocorrect changed PHP to phone in my initial post! I hate autocorrect sometimes.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Sweet, so I don't need to store a pre and post crypt version. Saves on space. Woohoo.

Share this post


Link to post
Share on other sites

 You still you still haven't told us what your really trying to do. What is the point of all this code?

Share this post


Link to post
Share on other sites
1 minute ago, benanamen said:

 You still you still haven't told us what your really trying to do. What is the point of all this code?

What do you think?

Share this post


Link to post
Share on other sites
3 hours ago, requinix said:

What do you think?

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

Share this post


Link to post
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.

Share this post


Link to post
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

Edited by benanamen

Share this post


Link to post
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.

Edited by Karaethon
Forgot to include

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

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.