By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,061 Members | 1,523 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,061 IT Pros & Developers. It's quick & easy.

uploading file problems

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
lion wrote:
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


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
Jul 17 '05 #2

P: n/a
ad*********@hotmail.com (lion) wrote in message news:<1f**************************@posting.google. com>...
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


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
Jul 17 '05 #3

P: n/a
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
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

Jul 17 '05 #4

P: n/a
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
Jul 17 '05 #5

P: n/a
> 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


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
Jul 17 '05 #6

P: n/a
ad*********@hotmail.com (lion) wrote in message news:<1f**************************@posting.google. com>...
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


are you getting the same errors?

please write your modified code and errors you are getting.

-- Rahul
Jul 17 '05 #7

P: n/a
That was just the ticket - works perfect!

thankyou very much Rahul

Lion
Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.