Earunder
02-29-2008, 04:31 PM
Hi all,
I've been having problems with uploading images and setting the correct permissions.
The code will follow shortly.
The image uploads ok, i can download the image via ftp and view it so I know that it hasn't been corrupted. I go to check the permissions of the newly uploaded image but the permissions are set to:
Owner Group Others
X - -
X - -
- - -
The permissions for the images folder is 777.
The location of the upload image file is within a restricted access directory as only members of staff will have permission to upload new images.
www.mysite.com/folder1(restricted)/folder2(restricted)/uploadimage.php
I'm not sure the location of the imageupload file makes that much of a difference???
Any who the code:
if($_POST["action"] == "Upload Image")
{
unset($imagename);
if(!isset($_FILES) && isset($HTTP_POST_FILES))
$_FILES = $HTTP_POST_FILES;
if(!isset($_FILES['image_file']))
$error["image_file"] = "An image was not found.";
$imagename = basename($_FILES['image_file']['name']);
if(empty($imagename))
$error["imagename"] = "The name of the image was not found.";
if(empty($error))
{
$newimage = "../../images/" . $imagename;
$partid = $_POST['partid'];
mysql_select_db($database_vwpconn00, $vwpconn00);
$dbfilename = $imagename;
$sq0 = mysql_query("UPDATE parts SET imageurl = '$dbfilename' WHERE partid = '$partid'") or die (mysql_error());
chmod("../../images/".$imagename, `0777`);
$result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage);
if(empty($result))
$error["result"] = "There was an error moving the uploaded file.";
}
}
?>
<form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<?$_SERVER["PHP_SELF"];?>">
<p><input type="file" name="image_file" size="20"></p>
<p><input type="submit" value="Upload Image" name="action">
<input name="partid" type="hidden" id="partid" value="<?php echo $_GET['partid'];?>">
</p>
</form>
<?
if(is_array($error))
{
while(list($key, $val) = each($error))
{
echo $val;
echo "<br>\n";
}
}
?>
I've been having problems with uploading images and setting the correct permissions.
The code will follow shortly.
The image uploads ok, i can download the image via ftp and view it so I know that it hasn't been corrupted. I go to check the permissions of the newly uploaded image but the permissions are set to:
Owner Group Others
X - -
X - -
- - -
The permissions for the images folder is 777.
The location of the upload image file is within a restricted access directory as only members of staff will have permission to upload new images.
www.mysite.com/folder1(restricted)/folder2(restricted)/uploadimage.php
I'm not sure the location of the imageupload file makes that much of a difference???
Any who the code:
if($_POST["action"] == "Upload Image")
{
unset($imagename);
if(!isset($_FILES) && isset($HTTP_POST_FILES))
$_FILES = $HTTP_POST_FILES;
if(!isset($_FILES['image_file']))
$error["image_file"] = "An image was not found.";
$imagename = basename($_FILES['image_file']['name']);
if(empty($imagename))
$error["imagename"] = "The name of the image was not found.";
if(empty($error))
{
$newimage = "../../images/" . $imagename;
$partid = $_POST['partid'];
mysql_select_db($database_vwpconn00, $vwpconn00);
$dbfilename = $imagename;
$sq0 = mysql_query("UPDATE parts SET imageurl = '$dbfilename' WHERE partid = '$partid'") or die (mysql_error());
chmod("../../images/".$imagename, `0777`);
$result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage);
if(empty($result))
$error["result"] = "There was an error moving the uploaded file.";
}
}
?>
<form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<?$_SERVER["PHP_SELF"];?>">
<p><input type="file" name="image_file" size="20"></p>
<p><input type="submit" value="Upload Image" name="action">
<input name="partid" type="hidden" id="partid" value="<?php echo $_GET['partid'];?>">
</p>
</form>
<?
if(is_array($error))
{
while(list($key, $val) = each($error))
{
echo $val;
echo "<br>\n";
}
}
?>