tags:

views:

59

answers:

3

Hi, I am uploading files to server. I found a function like

$sha1 = sha1_file($filename);

at http://www.tuxradar.com/practicalphp/8/15/0

So I was wonder whether or not $filename should point to the actual file with path or just the filename?

$_FILES['upload']['name'] will do it right?

A: 

Nope, wrong.
Why can't you just try it and see?

According to manual page, the path to uploaded file is in the $_FILES['upload']['tmp_name'] variable

Col. Shrapnel
i tired it..it gave error..
pradeep
@pradeep when getting errors, please *always* quote them in full. Everything else is wasting your fellow users' time.
Pekka
@pradeep well if you get an error, can't you conclude yourself, if $_FILES['upload']['name'] will do it or not? Looks like it's not?
Col. Shrapnel
I totally disagree with the attitude, but this doesn't deserve a -1 (or a +1 for that matter). Shrapnel is never nice, but often right. The OP should get off his laurels and get to testing rather than asking such naive questions.
Justin Johnson
@Justin Johnson: attitude is what matters here. The only intention behind posts like this is to show how smart the poster is. -1.
stereofrog
@stereofrog actually you can't tell what is the intention here. Please, add "in my humble assumption" to your further expressions.
Col. Shrapnel
+1 for now he has appended a true answer.
Majid
+4  A: 

Read up on the basics of handling file uploads in PHP

Preferably, do a move_uploaded_file() first, then in the target location, fetch the checksum.

Pekka
as a matter of fact, there is no difference, when to calculate. Temporary location just as good as target one.
Col. Shrapnel
+3  A: 

The path to uploaded file is $_FILES["upload"]["tmp_name"]

so if you haven't moved the uploaded file the function call would be

$sha1 = sha1_file($_FILES["upload"]["tmp_name"]);
ovais.tariq