Fopen failure

Fopen failure

am 24.01.2008 11:54:42 von faraz_mit

HI Guys,
I am making a php file which gathers data from a form and sends an
email with attachment. Here is a small part of that:

$filename = $_FILES['document_file_name']['name'];
$path = $_FILES['document_file_name']['tmp_name'];
$file =$path."/".$filename;
echo ($file); /* which is /var/tmp/phpB2TeJi/DSC_0082.jpg */

$handle = fopen($file, "r");
if(!($handle = fopen($file, 'r'))) echo "File failed to open";

Now when i run the code i get the following warnings:

Warning: fopen(/var/tmp/phpB2TeJi/DSC_0082.jpg) [function.fopen]:
failed to open stream: Not a directory in sendmailattach.php on line
17

Warning: fopen(/var/tmp/phpB2TeJi/DSC_0082.jpg) [function.fopen]:
failed to open stream: Not a directory in sendmailattach.php on line
18
File failed to open

Can somebody tell me please what is wrong with the way i call fopen.
I am running on a shared server and also tried different permissions
such as r and rb.

Thanks in advance
Ross

Re: Fopen failure

am 24.01.2008 12:09:10 von Erwin Moller

faraz_mit wrote:
> HI Guys,
> I am making a php file which gathers data from a form and sends an
> email with attachment. Here is a small part of that:
>
> $filename = $_FILES['document_file_name']['name'];
> $path = $_FILES['document_file_name']['tmp_name'];
> $file =$path."/".$filename;
> echo ($file); /* which is /var/tmp/phpB2TeJi/DSC_0082.jpg */

From php.net:

$_FILES['userfile']['tmp_name']

The temporary filename of the file in which the uploaded file was
stored on the server.

You already HAVE the full path to the file.
It is NOT a directory, but a filename.
Do not add the $_FILES['document_file_name']['name'] to it, and you
should be fine.

Regards,
Erwin Moller

>
> $handle = fopen($file, "r");
> if(!($handle = fopen($file, 'r'))) echo "File failed to open";
>
> Now when i run the code i get the following warnings:
>
> Warning: fopen(/var/tmp/phpB2TeJi/DSC_0082.jpg) [function.fopen]:
> failed to open stream: Not a directory in sendmailattach.php on line
> 17
>
> Warning: fopen(/var/tmp/phpB2TeJi/DSC_0082.jpg) [function.fopen]:
> failed to open stream: Not a directory in sendmailattach.php on line
> 18
> File failed to open
>
> Can somebody tell me please what is wrong with the way i call fopen.
> I am running on a shared server and also tried different permissions
> such as r and rb.
>
> Thanks in advance
> Ross

Re: Fopen failure

am 25.01.2008 07:31:57 von AnrDaemon

Greetings, faraz_mit.
In reply to Your message dated Thursday, January 24, 2008, 13:54:42,

In addition to the Erwin's post,

> $handle = fopen($file, "r");
> if(!($handle = fopen($file, 'r'))) echo "File failed to open";

Why You trying to open the file twice?

> Can somebody tell me please what is wrong with the way i call fopen.
> I am running on a shared server and also tried different permissions
> such as r and rb.

"r" and "rb" is not a permissions, but opening modes. "b" suffix telling PHP
to read file in binary mode.


--
Sincerely Yours, AnrDaemon