Connecting Tech Pros Worldwide Forums | Help | Site Map

uploading file problems

lion
Guest
 
Posts: n/a
#1: Jul 17 '05
I get these errors when uploading images via a web page:
(the page still uploads the images but reports these errors?)

Warning: fopen(D:\php\uploadtemp\php1FC7.tmp) [function.fopen]: failed
to create stream: No error in
D:\webspace\me.co.uk\wwwroot\test\Live.php on line 105

Warning: Wrong parameter count for filesize() in
D:\webspace\me.co.uk\wwwroot\test\Live.php on line 109

Warning: fread(): supplied argument is not a valid stream resource in
D:\webspace\me.co.uk\wwwroot\test\Live.php on line 109

Warning: Cannot modify header information - headers already sent by
(output started at D:\webspace\me.co.uk\wwwroot\test\Live.php:105) in
D:\webspace\me.co.uk\wwwroot\test\Live.php on line 138

This is the code at these errors:

105 = // Open file for binary reading ('rb')
$tempfile = fopen($uploadfile0,$uploadfile1,'rb');

109 = // Read the entire file into memory using PHP's
// filesize function to get the file size.
$filedata = fread($tempfile,filesize($uploadfile0,$uploadfile1 ));

138 = header('location: ' . $_SERVER['PHP_SELF']);

any one help?

I don't get this problem locally on apache 1.3.26 (win32) running php
4.2.2 BUT this happens when i use the same file on my live server
running php 4.3.0 on Windows NT

cheers Lion

Andreas Paasch
Guest
 
Posts: n/a
#2: Jul 17 '05

re: uploading file problems


lion wrote:
[color=blue]
> I get these errors when uploading images via a web page:
> (the page still uploads the images but reports these errors?)
>
> Warning: fopen(D:\php\uploadtemp\php1FC7.tmp) [function.fopen]: failed
> to create stream: No error in
> D:\webspace\me.co.uk\wwwroot\test\Live.php on line 105
>
> Warning: Wrong parameter count for filesize() in
> D:\webspace\me.co.uk\wwwroot\test\Live.php on line 109
>
> Warning: fread(): supplied argument is not a valid stream resource in
> D:\webspace\me.co.uk\wwwroot\test\Live.php on line 109
>
> Warning: Cannot modify header information - headers already sent by
> (output started at D:\webspace\me.co.uk\wwwroot\test\Live.php:105) in
> D:\webspace\me.co.uk\wwwroot\test\Live.php on line 138
>
> This is the code at these errors:
>
> 105 = // Open file for binary reading ('rb')
> $tempfile = fopen($uploadfile0,$uploadfile1,'rb');
>
> 109 = // Read the entire file into memory using PHP's
> // filesize function to get the file size.
> $filedata = fread($tempfile,filesize($uploadfile0,$uploadfile1 ));
>
> 138 = header('location: ' . $_SERVER['PHP_SELF']);
>
> any one help?
>
> I don't get this problem locally on apache 1.3.26 (win32) running php
> 4.2.2 BUT this happens when i use the same file on my live server
> running php 4.3.0 on Windows NT
>
> cheers Lion[/color]

I had a similar problem, got it solved by setting open_basedir in php.ini to
correct value.

You should go to www.php.net and read the manual on open_basedir for further
info as I don't have it here in my head ...

HTH,

/Andreas
--
Registeret Linux user #292411
Rahul Anand
Guest
 
Posts: n/a
#3: Jul 17 '05

re: uploading file problems


adamslionel@hotmail.com (lion) wrote in message news:<1f72d2de.0312081336.23484ace@posting.google. com>...[color=blue]
> I get these errors when uploading images via a web page:
> (the page still uploads the images but reports these errors?)
>
> Warning: fopen(D:\php\uploadtemp\php1FC7.tmp) [function.fopen]: failed
> to create stream: No error in
> D:\webspace\me.co.uk\wwwroot\test\Live.php on line 105
>
> Warning: Wrong parameter count for filesize() in
> D:\webspace\me.co.uk\wwwroot\test\Live.php on line 109
>
> Warning: fread(): supplied argument is not a valid stream resource in
> D:\webspace\me.co.uk\wwwroot\test\Live.php on line 109
>
> Warning: Cannot modify header information - headers already sent by
> (output started at D:\webspace\me.co.uk\wwwroot\test\Live.php:105) in
> D:\webspace\me.co.uk\wwwroot\test\Live.php on line 138
>
> This is the code at these errors:
>
> 105 = // Open file for binary reading ('rb')
> $tempfile = fopen($uploadfile0,$uploadfile1,'rb');
>
> 109 = // Read the entire file into memory using PHP's
> // filesize function to get the file size.
> $filedata = fread($tempfile,filesize($uploadfile0,$uploadfile1 ));
>
> 138 = header('location: ' . $_SERVER['PHP_SELF']);
>
> any one help?
>
> I don't get this problem locally on apache 1.3.26 (win32) running php
> 4.2.2 BUT this happens when i use the same file on my live server
> running php 4.3.0 on Windows NT
>
> cheers Lion[/color]

Hi,

Please check the following:

LINE 105: fopen() function takes only a single file name argument and
the mode.
LINE 109: filesize() function takes only a single argument
LINE 138: With above two errors fixed this error will also get fixed.

Following is the correct syntax
fopen: resource fopen ( string filename, string mode [, int
use_include_path [, resource zcontext]] )

filesize: int filesize ( string filename )

-- Rahul
lion
Guest
 
Posts: n/a
#4: Jul 17 '05

re: uploading file problems


cheers guys!

one thing though regarding Rahul suggestion - I need to upload two
files (a big pic and its thumbnail) will I not be able to do this at
once if that is the case?

I'll give it a go

I guess I could put it in a loop...?

cheers
[color=blue]
> LINE 105: fopen() function takes only a single file name argument and
> the mode.
> LINE 109: filesize() function takes only a single argument
> LINE 138: With above two errors fixed this error will also get fixed.
>
> Following is the correct syntax
> fopen: resource fopen ( string filename, string mode [, int
> use_include_path [, resource zcontext]] )
>
> filesize: int filesize ( string filename )
>
> -- Rahul[/color]
lion
Guest
 
Posts: n/a
#5: Jul 17 '05

re: uploading file problems


right, I've tried just passing one file upload to the script but it
still does'nt work and reports the same errors, does any one know why
this works fine with php 4.2.2 on apache 1.3.26...? but not on my live
host which has php 4.3...

doesnt add up...

lion
Rahul Anand
Guest
 
Posts: n/a
#6: Jul 17 '05

re: uploading file problems


> cheers guys![color=blue]
>
> one thing though regarding Rahul suggestion - I need to upload two
> files (a big pic and its thumbnail) will I not be able to do this at
> once if that is the case?
>
> I'll give it a go
>
> I guess I could put it in a loop...?
>
> cheers[/color]

Hi again,

Multiple files can be uploaded by running a loop and processing file
in iteration.

Following is the an example of caode that can handle multiple files
upload:

// Start of code
<?
if(!empty($_FILES))
{
$uploaddir = "../NewsLetterImages/";
$errorMessage =
array(
1=>"File exceeds the 2 MB limit" ,
2=>"File exceeds the 2 MB limit",
3=>"Only partially uploaded.",
);

foreach($_FILES['htmlImageFiles']['name'] as $vk=>$vv)
{
if(!empty($vv))
{
if(!file_exists($uploaddir . $vv) &&
$_FILES['htmlImageFiles']['error'][$vk] == 0)
move_uploaded_file($_FILES['htmlImageFiles']['tmp_name'][$vk],
$uploaddir . $vv);
else
{
$message = $vv;
if($_FILES['htmlImageFiles']['error'][$vk] != 0)
$message .= " (".$errorMessage[$_FILES['htmlImageFiles']['error'][$vk]].")
";
else
$message .= " (File already exists) ";
$errorFiles[] = $message;
}
}
}
if(!empty($errorFiles))
{
// Error Uploading files
$_HEADER_="Error Uploading Files";
$_MESSAGE_="Sorry! Unable to uplaod following files:-<p>
".implode('<br>',$errorFiles);
$_MESSAGE_ .= "<p><a href='uploadForm.html'>Go back to try
again</a><p>Please note you can not upload duplicate files or files of
size greater than 2 MB.";
include_once "errorPage.php";
exit;
}
// Success
header("Location: succesPage.php");
exit;
}
?>
// End of code

In my HTML form I used this code

<!-- START HTML CODE -->

<table>
<tr>
<td align="center"><h3>Upload Newsletter Images</h3></td>
</tr>
<tr>
<td class="normal_style">
<b>Image File 1</b>
<input type="file" name="htmlImageFiles[]"><p>
</td>
</tr>
<tr>
<td class="normal_style">
<b>Image File 2</b>
<input type="file" name="htmlImageFiles[]"><p>
</td>
</tr>
<tr>
<td class="normal_style">
<b>Image File 3</b>
<input type="file" name="htmlImageFiles[]"><p>
</td>
</tr>
<tr>
<td class="normal_style">
<b>Image File 4</b>
<input type="file" name="htmlImageFiles[]"><p>
</td>
</tr>
</table>

<!-- END HTML CODE -->


I guess this will help.

-- Rahul
Rahul Anand
Guest
 
Posts: n/a
#7: Jul 17 '05

re: uploading file problems


adamslionel@hotmail.com (lion) wrote in message news:<1f72d2de.0312091332.79828e26@posting.google. com>...[color=blue]
> right, I've tried just passing one file upload to the script but it
> still does'nt work and reports the same errors, does any one know why
> this works fine with php 4.2.2 on apache 1.3.26...? but not on my live
> host which has php 4.3...
>
> doesnt add up...
>
> lion[/color]

are you getting the same errors?

please write your modified code and errors you are getting.

-- Rahul
lion
Guest
 
Posts: n/a
#8: Jul 17 '05

re: uploading file problems


That was just the ticket - works perfect!

thankyou very much Rahul

Lion
Closed Thread