Home > PHP: Visual QuickStart Guide (1st Ed) > Topic

HTTP wrapper does not support writeable connections

Posted by ladraove 
This forum is now read only. You can not log in or make any changes. Please use the new forum linked above.
As of March 14, 2011, this forum has been replaced and is permanently set to read-only mode. This means you can view any existing post but cannot open new posts or reply to existing ones. The new forum is located athttp://www.larryullman.com/forums/If you need to post a message, you'll need to register there. If you have to post in order to follow up on a thread started here, well, that's going to be a bit of a pain. I would recommend just posting the appropriate information, or copying the original text from here, or linking to your thread here. I apologize for the inconvenience but this purge will make for better forums in the long run. Thanks.
What does this warning mean, and how do I fix it?

Warning: fopen(http://192.168.1.101/boards/areas/ooc/ooc/test/94064636.html): failed to open stream: HTTP wrapper does not support writeable connections. in C:\apache\htdocs\boards\threadprocess.php on line 33

The code that generates this error (last line is line 33):

$filelocation = $homedirectory . "areas/" . $area . "/" . $region . "/" . $board . "/" . $location . ".html";
$open = fopen ("$filelocation", "a");



I am running the latest version of php; I downloaded and installed it only a week ago. I am running this code using Apache on my home computer, which uses Windows XP media center (which I am told is a version of Pro).
It means that the script won't let you write to a file via []. Use the local, absolute path instead.

Larry
To try Larry's suggestion, I *think* you would just need to replace $homedirectory with $_SERVER['DOCUMENT_ROOT'] OR possibly realpath($_SERVER['DOCUMENT_ROOT']).

Hey guys!
I just want to say Thanks for the help. I had the same problem, and I just solved it. Tanks.
Glad we could help and thanks for saying so.

Larry
Re: HTTP wrapper does not support writeable connections
October 21, 2004 11:49AM
Hi all.

Great post - steered me in the right direction.

I am trying to write a file in a folder called 'content' which resides in my server root. I can successfully upload the file using '$_SERVER['DOCUMENT_ROOT']' as the location, but when I try '$_SERVER['DOCUMENT_ROOT/content/'] it still writes to the root.

I'm pretty new to PHP so may be overlooking something or not doing something really obvious!

Any help gratefully read and digested.

J
Re: HTTP wrapper does not support writeable connections
October 27, 2004 06:43PM
You can't refer to $_SERVER['DOCUMENT_ROOT/content/']. See, $_SERVER is an array varaible and 'DOCUMENT_ROOT' is an index for a specific element in that array. So $_SERVER['DOCUMENT_ROOT/content/'] has no meaning. What you want to do instead is refer to
$_SERVER['DOCUMENT_ROOT'] . '/content/'

Best Wishes,
Larry

Writer/Web Developer/Instructor
Forum Moderator
Re: HTTP wrapper does not support writeable connections
October 27, 2004 07:07PM
Ah, I see. Thanks for the reply Larry.
Re: HTTP wrapper does not support writeable connections
October 18, 2005 12:22AM
I should add my thanks for this post as well. I have used this not once but at least twice. I seem to wind up with this problem every time I change my .htaccess file...

www.FluffyCat.com
Re: HTTP wrapper does not support writeable connections
October 18, 2005 12:24AM
Glad it helped and thanks for saying so!

Best Wishes,
Larry

Writer/Web Developer/Instructor
Forum Moderator
Re: HTTP wrapper does not support writeable connections
November 10, 2005 10:33AM
Hi,

I have the same problem, but i want to upload a file to other server, not to the one where is my page.
What can i do then? $_SERVER['DOCUMENT_ROOT'] is for the server of the page so i cant use, no?

Thanks
Re: HTTP wrapper does not support writeable connections
November 10, 2005 03:02PM
I'm not sure that I understand your question. Could you please be more explicit?

Best Wishes,
Larry

Writer/Web Developer/Instructor
Forum Moderator
Re: HTTP wrapper does not support writeable connections
November 11, 2005 07:16AM
Sorry for my bad explanation.

I have the "HTTP wrapper does not support writeable connections" when i try to upload a file to a host.
Reading the posts of this thread i see how resolve this using the global variable $_SERVER['DOCUMENT_ROOT'] to avoid the use of http.

Well, i have one host with my web, and have another host only for pictures. I want to upload pictures to this second host. If i use $_SERVER['DOCUMENT_ROOT'], i will have the local/absolute path of the first host (where the php file is executed), and i need the local/absolute path of the second host. How can i do that or isnt it possible?

Thanks again
Re: HTTP wrapper does not support writeable connections
November 11, 2005 03:52PM
It sounds like you need to use PHP's FTP functions to move the files from the one server to the other server. See the PHP manual for examples.

Best Wishes,
Larry

Writer/Web Developer/Instructor
Forum Moderator
Re: HTTP wrapper does not support writeable connections
March 17, 2006 04:35AM
Sorry, this is probably a dumb and redundant question but I'm having the same problem only with a simple uploading form:
[vgf.awardspace.com] here's the line:

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $_SERVER['DOCUMENT_ROOT']. $_FILES['userfile']['name']))

is this a problem with restrictions on the server? (seeing as it's free webspace...) or did I just make a stupid mistake?
Re: HTTP wrapper does not support writeable connections
March 18, 2006 04:30PM
You haven't provided enough information to assist. What version of PHP are you using? What error message are you getting? Do you know what the value of $_SERVER['DOCUMENT_ROOT'] is? Have you set the permissions properly?

Best Wishes,
Larry

Writer/Web Developer/Instructor
Forum Moderator
Re: HTTP wrapper does not support writeable connections
March 21, 2006 04:37AM
Hi,
I'm having a problem running script 11.4 file_upload.php
The system is Windows NT WEBA40 5.2 build 3790 IIS and is running php 4.4.1.

I recieve 2 errors
Warning: move_uploaded_file(admin/images/ballons01.jpg): failed to open stream: No such file or directory in d:\inetpub\thebuxmontteam\admin\upload_file.php on line 20

Warning: move_uploaded_file(): Unable to move 'C:\PHP\uploadtemp\php206.tmp' to 'admin/images/ballons01.jpg' in d:\inetpub\thebuxmontteam\admin\upload_file.php on line 20

I've tried using realpath($_SERVER['DOCUMENT_ROOT']) and I still get the same result.

Below is the script

The directory I'm trying to upload to has a chmod of 777
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"[www.w3.org];
<html xmlns="[www.w3.org];
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Upload a File</title>
</head>
<body>
<?php // Script 11.4 - upload_file.php
// This script displays and handles an HTML form.
// This script takes a file upload and stores it on the server.

// Address error handing.
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);

if (isset ($_POST['submit'])) { // Handle form.

// Try to move the uploaded file.
if (move_uploaded_file ($_FILES['thefile']['tmp_name'], "admin/images/{$_FILES['thefile']['name']}")) {
//if (move_uploaded_file ($_FILES['thefile']['tmp_name'], realpath($_SERVER['DOCUMENT_ROOT'])."\images" )) {
print '<p>Your file has been uploaded.</p>';

} else { // Problem!

print '<p>Your file could not be uploaded because: <b>';

// Print a message based upon the error.
switch ($_FILES['thefile']['error']) {
case 1:
print 'The file exceeds the upload_max_filesize setting in php.ini';
break;
case 2:
print 'The file exceeds the MAX_FILE_SIZE setting in the HTML form';
break;
case 3:
print 'The file was only partially uploaded';
break;
case 4:
print 'No file was uploaded';
break;
}
print '</b>.</p>';
}

} // End of SUBMIT IF.

// Leave PHP and display the form.
?>

<form action="upload_file.php" enctype="multipart/form-data" method="post">
<p>Upload a file using this form: <br /><br />
<input type="hidden" name="MAX_FILE_SIZE" value="130000" />
<input type="file" name="thefile" /><br /><br />
<input type="submit" name="submit" value="Upload This File" />
</p>
</form>
</body>
</html>

Thanks
BDiv
Re: HTTP wrapper does not support writeable connections
March 21, 2006 04:42AM
Sorry for the vague question, and thanks for the response but I figured out my problem. :) simply had the wrong directory...
Re: HTTP wrapper does not support writeable connections
March 21, 2006 03:04PM
BDiv, I suspect your problem is because you're not properly referring to the directory into which the image should be moved. If you still have problems with this, please start a NEW THREAD (your post is unrelated to the topic of HTTP wrappers) in the RIGHT FORUM (you've posted in the wrong one, as the PHP VQS 1st Ed has a different Script 11.4).

Best Wishes,
Larry

Writer/Web Developer/Instructor
Forum Moderator
Re: HTTP wrapper does not support writeable connections
May 04, 2006 09:47AM
Larry Wrote:
-------------------------------------------------------
> It sounds like you need to use PHP's FTP functions
> to move the files from the one server to the other
> server. See the PHP manual for examples.

i have just purchased the second edition and i am brand new to php but this is an issue i am trying to solve without luck for 2 days.

i have looked through the book but i cant find any example of this at all - would you be so kind to point me in the right direction of where they can be found.

thank you very much



Edited 1 time(s). Last edit at 05/04/2006 02:49PM by Larry.
Re: HTTP wrapper does not support writeable connections
May 04, 2006 02:50PM
First of all, just so you know, you posted this question in the forum for the FIRST edition. Doesn't matter for this question but could matter if you have a book-specific question later.

Second, the right direction is always the PHP manual. The alternative right direction is always a search online. If you have a specific question, please post all the relevant details here.

Best Wishes,
Larry

Writer/Web Developer/Instructor
Forum Moderator
Re: HTTP wrapper does not support writeable connections
May 18, 2006 08:20AM
my apologies for posting in the wrong forum. i still cannot find an answer to my problem and unfortunately i feel somewhat of a fool for trying to post a half-assed question on here as i am no expert, therefore i will not waste any more of your time.

good book - i will keep working thru it (progress is slow but i hope rewarding)

Re: HTTP wrapper does not support writeable connections
November 01, 2010 10:10AM
Just install PHP and apache into another drive...
Sometimes, the drive that operating system is installed (i.e. C:\), protects file from uploading file.

- Md. Zikrul Ahsan