Php upload error

thefattredd

New Member
Messages
5
Reaction score
0
Points
0
I am trying to create a script that allows admins to update a feed that consists of an image and a bunch of text. The processing the text only works just fine, but I get the following error with the image:

Warning: copy() [function.copy]: open_basedir restriction in effect. File() is not within the allowed path(s): (/home/:/tmp) in /home/fattredd/public_html/test/newlocation.php on line 11
Error uploading

What does this mean? Heres my processing script:

PHP:
<?php
	require_once 'conn.php';
	include 'parts/header.php';
	$name = $_POST['name'];
	$link = $_POST['link'];
	$description = $_POST['description'];
	$image_alt - $_POST['image_alt'];
	
	$path= "uploads/".$HTTP_POST_FILES['image']['name'];
	if($image !=none) {
		if(copy($HTTP_POST_FILES['image']['tmp_name'], $path)) {
			echo "File Name :".$HTTP_POST_FILES['image']['name']."<BR/>"; 
			echo "File Size :".$HTTP_POST_FILES['image']['size']."<BR/>"; 
			echo "File Type :".$HTTP_POST_FILES['image']['type']."<BR/>"; 
			echo "<img src=\"$path\" width=\"150\" height=\"150\"><br><br><br><br><br>";
		} else {
			echo "Error uploading";
		}
	}
	
	$sql = "INSERT INTO `locations` (link, description, image_url, image_alt)" .
			" VALUES (" . $link . ", " . $description . ", " . $path . ", " .
			$image_alt . ")";
	$result=mysql_query($sql);
	
		echo "<div class=\"content_entry\">" .
			"<div class=\"thumbnail\"><img src=\"" . $HTTP_POST_FILES['image']['name'] . "\" width=\"118\" height=\"88\" alt=\"" . $image_alt . "\" /></div>" .
			"<div class=\"entry_text\">" .
			"<h3>" .
			"<a href=\"" . $link . "\">" . $name . "</a>" .
			"<br />" .
			"</h3>" .
			"<p>" . $description . "</p>" .
			"</div>" .
			"<div class=\"clearthis\">&nbsp;</div>" .
			"</div>";
?>

I use conn.php to connect to my database and parts/header.php to format the page
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Read up on the open_basedir directive. Anything outside the /home and /tmp hierarchies can't be accessed from PHP. Print the path on any line that generates a notice to get a better idea of what's happening. You can always search the forums for more information.
 
Last edited:

kadai

New Member
Messages
51
Reaction score
2
Points
0
Very interesting that it does not work.

First of all, I wonder why you use "$HTTP_POST_FILES" instead of "$_FILES", I recommend the second because that is the way it should be used by now (PHP5 and latter) and my scripts works correctly with that variable.

A way to debug it is to (having a script that simply uploads the image) see what does PHP have for the FILES array:

Code:
print_r($_FILES);

And of course, if you get an empty array, it may be an indication that you are not using the correct 'name' in the array's key.

For example, the "upload" might be different if you are using a "name" indicator in your input field.

Having <input name=myupload type=file> will generate an usable array like this:
$_FILES['myupload']

Just notations, to make sure that you are trying to copy the correct file.
 

thefattredd

New Member
Messages
5
Reaction score
0
Points
0
I'm only using $HTTP_POST_FILES because that was suggested to me by a friend. I'm kinda new with uploading files and such. Thanks a lot for your input and help to solving this problem. I'll try it out as soon as i can
 

kadai

New Member
Messages
51
Reaction score
2
Points
0
You welcome :3
One way to debug efficiently your scripts is to print variables in an arbitrary way to see if they are having an expected value when entering a processing stage (In your case, moving and handling the uploaded file)

Now, giving it even a second close look, I detected this:
Code:
if($image !=none) {

But then I have not seen where $image was set a value, so, it is by nature NULL (undeclared) what can be also causing the problem.
 

varunaroli

New Member
Messages
4
Reaction score
0
Points
0
You just try this code....



<?php

if ((($_FILES["image"]["type"] == "image/gif")
|| ($_FILES["image"]["type"] == "image/jpeg")
|| ($_FILES["image"]["type"] == "image/bmp")
|| ($_FILES["image"]["type"] == "image/pjpeg")))
{
if ($_FILES["image"]["error"] > 0)
{
echo "Return Code: " . $_FILES["image"]["error"] . "<br />";
}
else
{

if (file_exists("upload/" . $_FILES["image"]["name"]))
{

}
else
{
move_uploaded_file($_FILES["image"]["tmp_name"],"upload/" . $_FILES["image"]["name"]);

}
$path=$_FILES["image"]["name"];

?>
 
Top