Uploading file architecture

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
akagi07
Forum Newbie
Posts: 3
Joined: Mon Jun 07, 2010 8:41 pm

Uploading file architecture

Post by akagi07 »

Hi, I'm new here.
Basically, I am now designing some web forms for my company using PHP and MS SQL.
I am now at this point whereby I need to create a upload form..

Not sure if this topic is rightfully to be here or to be in theory and design forum.. nevertheless, please assist if any of you knows :)

My current handling is convert the uploaded file:

Code: Select all

if ($_FILES["fSHORT_FILE"]["error"] > 0){
	echo "Return Code: " . $_FILES["fSHORT_FILE"]["error"] . "<br />";
	fileerror="x";
}else if(file_exists("upload/".$_FILES["fSHORT_FILE"]["name"])){
	echo $_FILES["fSHORT_FILE"]["name"] . " already exists. ";
	fileerror="x";
}else{
	$tmpFileName="";
	move_uploaded_file($_FILES["fSHORT_FILE"]["tmp_name"],"upload/" . $_FILES["fSHORT_FILE"]["name"]);
	$tmpFileName = $_FILES['fSHORT_FILE']['tmp_name'];
	$dataString = file_get_contents($tmpFileName);
	$arrData = unpack("H*hex", $dataString);
	$sSHORT_FILE = "0x".$arrData['hex'];
}
I am aware that move_uploaded_file — Moves an uploaded file to a new location from PHP context. but not sure if my above codes are logical or wasting time?
I am saving to my DB as Hex, 0x30783733363433343631363436643064306132343434333434313336366432343633363130643061306430613064306133393337333733303337333933313337

And now trying to figure out to download as stream, which realized I'm doing extra work.

My workaround now, using the same method, move_upload_files, my logic design will moved the upload file to the file server which involved folder permission. So in my DB, I will store the file path rather than the raw data itself. And when I hit download button, the web form will download the file from the file server with permission to (Execute only).

But I read some articles that move_upload_files did was move the files to a temp dir, and once done, the file will be gone.. is this true and is my methodology above workable?

and in my php.ini,
;upload_tmp_dir = I have to set the upload folder here. But do I still need to specify in my script?
User avatar
phdatabase
Forum Commoner
Posts: 83
Joined: Fri May 28, 2010 10:02 am
Location: Fort Myers, FL

Re: Uploading file architecture

Post by phdatabase »

Once you use 'move_uploaded_file' it is no longer in the tmp_name. However, it is in the upload/name. So you can manipulate the tmp_name before move_uploaded_file or name afterward.
akagi07
Forum Newbie
Posts: 3
Joined: Mon Jun 07, 2010 8:41 pm

Re: Uploading file architecture

Post by akagi07 »

phdatabase wrote:Once you use 'move_uploaded_file' it is no longer in the tmp_name. However, it is in the upload/name. So you can manipulate the tmp_name before move_uploaded_file or name afterward.
thanks phdatabase.

so based on your point,
move_uploaded_file($_FILES["value1"]["value2"],"value3"]);

value1 = my html input control *upload filename*
value2 = the temp filename
value3 = the file server path which the file be reside in when upload is finished.

and if i were to perform validation on the input file, I will use value2 to validate right?
akagi07
Forum Newbie
Posts: 3
Joined: Mon Jun 07, 2010 8:41 pm

Re: Uploading file architecture

Post by akagi07 »

opps, yah missing 1 more question,

so in my php.ini,
the temp dir i set in the temp_dir is jus a temp storage which I can just igore and use the windows default right.
ultimately, its the final location which I need to specify in my php script to determine where the file will reside (eg in the server)
Post Reply