ungovernable
05-18-2008, 06:02 AM
Ok well my problem is really weird, i'll try to explain it the best i can
Basically i have this image upload script ive been working a lot on, and with the help of some peoples... so i really dont want to start it over
My problem is that when an image is upload, i won't be able to touch the physical file.. I cannot download it from the ftp to my computer, i cannot change the chmod, but i can rename the file
BUT, i tryed it on a different server and everything works perfectly
Daniel0 suggested the problem was caused by this:
It's because your user nor your group hasn't got write access to the file. It's probably owned by whatever user and group your web server is running as. Only root is allowed to change the ownership using chown so you'll have to give write permissions to all.
BUT... The script is creating a thumbnail file of the uploaded file, and i have no problem with the thumb file!! I can transfer it, change the chmod, etc...
here is what some user of phpfreaks suggested:
Apache may save your upload as one user, then when you modify the original image to create a thumb, php may save as another user. So if you edit without resizing, your permissions will match.
So basically this is where i'm stuck at.... could anyone PLEASE help me to fix this script? I would be really happy if i can get this to work
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
$headinclude
<title>$vboptions[bbtitle]</title>
</head>
<body>
<?php
include("db.php");
$bbuserinfo['userid'] = "1";
//This is the resize/sampler.
function resample($img, $max_w, $max_h, $type, $thumb)
{
switch ($type) {
case 2:
// get original images width and height
list($or_w, $or_h, $or_t) = getimagesize($img);
// obtain the image's ratio
$ratio = ($or_h / $or_w);
// original image
$or_image = imagecreatefromjpeg($img);
// resize image?
if ($or_w > $max_w || $or_h > $max_h) {
// resize by height, then width (height dominant)
if ($max_h < $max_w)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
// resize by width, then height (width dominant)
if ($max_w < $max_h)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
//Resize by neither (as it is equal anyways)
if ($max_w == $max_h)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
// copy old image to new image
$rs_image = @imagecreatetruecolor($rs_w, $rs_h);
@imagecopyresampled($rs_image, $or_image, 0, 0, 0, 0, $rs_w, $rs_h, $or_w, $or_h);
}
// image requires no resizing
else {
$rs_w = $or_w;
$rs_h = $or_h;
$rs_image = $or_image;
}
if($thumb == true)
{
$image = explode('/',$img);
$x = 0;
$num_dir = count($image)-1;
while($x < count($image)-1)
{
$pre_img .=$image[$x]."/";
$x++;
}
$img = $pre_img."/sml_".$image[count($image)-1];
$img;
}
// generate resized image
imagejpeg($rs_image, $img, 100);
return true;
break;
case 3:
// get original images width and height
list($or_w, $or_h, $or_t) = getimagesize($img);
// obtain the image's ratio
$ratio = ($or_h / $or_w);
// original image
$or_image = imagecreatefrompng($img);
// resize image?
if ($or_w > $max_w || $or_h > $max_h) {
// resize by height, then width (height dominant)
if ($max_h < $max_w)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
// resize by width, then height (width dominant)
if ($max_w < $max_h)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
//Resize by neither (as it is equal anyways)
if ($max_w == $max_h)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
// copy old image to new image
$rs_image = imagecreatetruecolor($rs_w, $rs_h);
imagecopyresampled($rs_image, $or_image, 0, 0, 0, 0, $rs_w, $rs_h, $or_w, $or_h);
}
// image requires no resizing
else {
$rs_w = $or_w;
$rs_h = $or_h;
$rs_image = $or_image;
}
if($thumb == true)
{
$image = explode('/',$img);
$img = $image[(count($image)-1)]."sml_".$image[count($image)];
print $img;
}
// generate resized image
imagepng($rs_image, $img, 100);
return true;
break;
case 4:
// get original images width and height
list($or_w, $or_h, $or_t) = getimagesize($img);
// obtain the image's ratio
$ratio = ($or_h / $or_w);
// original image
$or_image = imagecreatefromgif($img);
// resize image?
if ($or_w > $max_w || $or_h > $max_h) {
// resize by height, then width (height dominant)
if ($max_h < $max_w)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
// resize by width, then height (width dominant)
if ($max_w < $max_h)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
//Resize by neither (as it is equal anyways)
if ($max_w == $max_h)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
// copy old image to new image
$rs_image = imagecreatetruecolor($rs_w, $rs_h);
imagecopyresampled($rs_image, $or_image, 0, 0, 0, 0, $rs_w, $rs_h, $or_w, $or_h);
}
// image requires no resizing
else {
$rs_w = $or_w;
$rs_h = $or_h;
$rs_image = $or_image;
}
// generate resized image
if($thumb == true)
{
$image = explode('/',$img);
$img = $image[(count($image)-1)]."sml_".$image[count($image)];
print $img;
}
imagegif($rs_image, $img, 100);
return true;
break;
}
}
?>
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
<?php $headinclude;?>
<title><?php $vboptions['bbtitle'];?></title>
</head>
<body>
<br /><br /><br /><br />
<center>
<?php
$bbuserinfo['userid'] = "1";
if($bbuserinfo['userid'] != NULL)
{}
else
{
$url = 'connexion.php'; $timeout = 0;
header('Refresh: ' . $timeout . ';url=' . $url);
print'
<meta http-equiv="refresh" content="'.$timeout.';url='.$url.';">
<script type="text/javascript">
setTimeout(function(){window.location.replace("'.$url.'; ", '.($timeout * 0).');
</script>';
}
if($bbuserinfo['userid'])
{
print'
<form action="'.$_server['php-self'].'" method="post"
enctype="multipart/form-data" id="something" class="uniForm">
';
// @include("imgbands.php"); //
print'
<br /><hr />
<table>
<tr>
<td>
Uploader la photo (#1):
</td>
<td>
<input name="new_image" id="new_image" size="30" type="file" class="fileUpload" />
</td>
</tr>
<tr>
<td>
Description (optionel):
</td>
<td>
<INPUT TYPE="TEXT" NAME="infos" VALUE="" size="60">
</td>
</tr>
</table>
<INPUT TYPE="hidden" NAME="user" VALUE="'.$bbuserinfo['username'].'" size="60">
<input name="submit" type="submit" class="submitButton" value="AJOUTER L\'IMAGE" />
</form>
';
}
$band = $_POST['band'];
if($_POST['submit'])
{
$imagenamz = $_FILES['new_image']['name'];
$originalname = $_FILES['new_image']['name'];
$date = date('dmy');
$imagename = "$band" . "_" . $date . "_" . $originalname;
echo $imagename;
$vraidate = date('d/m/y');
$nom = $_POST['user'];
$infos = $_POST['infos'];
echo "<br />L'image a été ajouté dans l'album photos de <b>$band</b><hr><br />";
$source = $_FILES['new_image']['tmp_name'];
$target = "db/img/images/".$imagename;
move_uploaded_file($source, $target);
$imagepath = $imagename;
$save = "db/img/images/" . $imagepath; //This is the new fileyou saving
$file = "db/img/images/" . $imagepath; //This is the originalfile
list($width, $height, $att) = getimagesize($file) ;
$size = getimagesize($file);
$uploadx = $size[0];
$uploady = $size[1];
}
list($width, $height, $type, $attr) = getimagesize($target);
resample($target, 800, 800, $type, false);
resample($target, 150, 150, $type, true);
if(isset($_POST['submit'])){
// if file exists
// add to database
$filename = 'db/img/images/sml_".$imagepath."';
if (file_exists($filename)) {
$band = $_POST['band'];
$originalname = $_FILES['new_image']['name'];
$date = date('dmy');
$imagename = "$band" . "_" . $date . "_" . $originalname;
// echo $imagename;
$vraidate = date('d/m/y');
$nom = $_POST['user'];
$infos = $_POST['infos'];
$result = mysql_query("INSERT INTO bands_pics (id,band,url,date,infos,valide,user) VALUES ('NULL', '$band', '$imagename','$vraidate','$infos','0','$nom')");
}
}
?>
123
Basically i have this image upload script ive been working a lot on, and with the help of some peoples... so i really dont want to start it over
My problem is that when an image is upload, i won't be able to touch the physical file.. I cannot download it from the ftp to my computer, i cannot change the chmod, but i can rename the file
BUT, i tryed it on a different server and everything works perfectly
Daniel0 suggested the problem was caused by this:
It's because your user nor your group hasn't got write access to the file. It's probably owned by whatever user and group your web server is running as. Only root is allowed to change the ownership using chown so you'll have to give write permissions to all.
BUT... The script is creating a thumbnail file of the uploaded file, and i have no problem with the thumb file!! I can transfer it, change the chmod, etc...
here is what some user of phpfreaks suggested:
Apache may save your upload as one user, then when you modify the original image to create a thumb, php may save as another user. So if you edit without resizing, your permissions will match.
So basically this is where i'm stuck at.... could anyone PLEASE help me to fix this script? I would be really happy if i can get this to work
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
$headinclude
<title>$vboptions[bbtitle]</title>
</head>
<body>
<?php
include("db.php");
$bbuserinfo['userid'] = "1";
//This is the resize/sampler.
function resample($img, $max_w, $max_h, $type, $thumb)
{
switch ($type) {
case 2:
// get original images width and height
list($or_w, $or_h, $or_t) = getimagesize($img);
// obtain the image's ratio
$ratio = ($or_h / $or_w);
// original image
$or_image = imagecreatefromjpeg($img);
// resize image?
if ($or_w > $max_w || $or_h > $max_h) {
// resize by height, then width (height dominant)
if ($max_h < $max_w)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
// resize by width, then height (width dominant)
if ($max_w < $max_h)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
//Resize by neither (as it is equal anyways)
if ($max_w == $max_h)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
// copy old image to new image
$rs_image = @imagecreatetruecolor($rs_w, $rs_h);
@imagecopyresampled($rs_image, $or_image, 0, 0, 0, 0, $rs_w, $rs_h, $or_w, $or_h);
}
// image requires no resizing
else {
$rs_w = $or_w;
$rs_h = $or_h;
$rs_image = $or_image;
}
if($thumb == true)
{
$image = explode('/',$img);
$x = 0;
$num_dir = count($image)-1;
while($x < count($image)-1)
{
$pre_img .=$image[$x]."/";
$x++;
}
$img = $pre_img."/sml_".$image[count($image)-1];
$img;
}
// generate resized image
imagejpeg($rs_image, $img, 100);
return true;
break;
case 3:
// get original images width and height
list($or_w, $or_h, $or_t) = getimagesize($img);
// obtain the image's ratio
$ratio = ($or_h / $or_w);
// original image
$or_image = imagecreatefrompng($img);
// resize image?
if ($or_w > $max_w || $or_h > $max_h) {
// resize by height, then width (height dominant)
if ($max_h < $max_w)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
// resize by width, then height (width dominant)
if ($max_w < $max_h)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
//Resize by neither (as it is equal anyways)
if ($max_w == $max_h)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
// copy old image to new image
$rs_image = imagecreatetruecolor($rs_w, $rs_h);
imagecopyresampled($rs_image, $or_image, 0, 0, 0, 0, $rs_w, $rs_h, $or_w, $or_h);
}
// image requires no resizing
else {
$rs_w = $or_w;
$rs_h = $or_h;
$rs_image = $or_image;
}
if($thumb == true)
{
$image = explode('/',$img);
$img = $image[(count($image)-1)]."sml_".$image[count($image)];
print $img;
}
// generate resized image
imagepng($rs_image, $img, 100);
return true;
break;
case 4:
// get original images width and height
list($or_w, $or_h, $or_t) = getimagesize($img);
// obtain the image's ratio
$ratio = ($or_h / $or_w);
// original image
$or_image = imagecreatefromgif($img);
// resize image?
if ($or_w > $max_w || $or_h > $max_h) {
// resize by height, then width (height dominant)
if ($max_h < $max_w)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
// resize by width, then height (width dominant)
if ($max_w < $max_h)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
//Resize by neither (as it is equal anyways)
if ($max_w == $max_h)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
// copy old image to new image
$rs_image = imagecreatetruecolor($rs_w, $rs_h);
imagecopyresampled($rs_image, $or_image, 0, 0, 0, 0, $rs_w, $rs_h, $or_w, $or_h);
}
// image requires no resizing
else {
$rs_w = $or_w;
$rs_h = $or_h;
$rs_image = $or_image;
}
// generate resized image
if($thumb == true)
{
$image = explode('/',$img);
$img = $image[(count($image)-1)]."sml_".$image[count($image)];
print $img;
}
imagegif($rs_image, $img, 100);
return true;
break;
}
}
?>
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
<?php $headinclude;?>
<title><?php $vboptions['bbtitle'];?></title>
</head>
<body>
<br /><br /><br /><br />
<center>
<?php
$bbuserinfo['userid'] = "1";
if($bbuserinfo['userid'] != NULL)
{}
else
{
$url = 'connexion.php'; $timeout = 0;
header('Refresh: ' . $timeout . ';url=' . $url);
print'
<meta http-equiv="refresh" content="'.$timeout.';url='.$url.';">
<script type="text/javascript">
setTimeout(function(){window.location.replace("'.$url.'; ", '.($timeout * 0).');
</script>';
}
if($bbuserinfo['userid'])
{
print'
<form action="'.$_server['php-self'].'" method="post"
enctype="multipart/form-data" id="something" class="uniForm">
';
// @include("imgbands.php"); //
print'
<br /><hr />
<table>
<tr>
<td>
Uploader la photo (#1):
</td>
<td>
<input name="new_image" id="new_image" size="30" type="file" class="fileUpload" />
</td>
</tr>
<tr>
<td>
Description (optionel):
</td>
<td>
<INPUT TYPE="TEXT" NAME="infos" VALUE="" size="60">
</td>
</tr>
</table>
<INPUT TYPE="hidden" NAME="user" VALUE="'.$bbuserinfo['username'].'" size="60">
<input name="submit" type="submit" class="submitButton" value="AJOUTER L\'IMAGE" />
</form>
';
}
$band = $_POST['band'];
if($_POST['submit'])
{
$imagenamz = $_FILES['new_image']['name'];
$originalname = $_FILES['new_image']['name'];
$date = date('dmy');
$imagename = "$band" . "_" . $date . "_" . $originalname;
echo $imagename;
$vraidate = date('d/m/y');
$nom = $_POST['user'];
$infos = $_POST['infos'];
echo "<br />L'image a été ajouté dans l'album photos de <b>$band</b><hr><br />";
$source = $_FILES['new_image']['tmp_name'];
$target = "db/img/images/".$imagename;
move_uploaded_file($source, $target);
$imagepath = $imagename;
$save = "db/img/images/" . $imagepath; //This is the new fileyou saving
$file = "db/img/images/" . $imagepath; //This is the originalfile
list($width, $height, $att) = getimagesize($file) ;
$size = getimagesize($file);
$uploadx = $size[0];
$uploady = $size[1];
}
list($width, $height, $type, $attr) = getimagesize($target);
resample($target, 800, 800, $type, false);
resample($target, 150, 150, $type, true);
if(isset($_POST['submit'])){
// if file exists
// add to database
$filename = 'db/img/images/sml_".$imagepath."';
if (file_exists($filename)) {
$band = $_POST['band'];
$originalname = $_FILES['new_image']['name'];
$date = date('dmy');
$imagename = "$band" . "_" . $date . "_" . $originalname;
// echo $imagename;
$vraidate = date('d/m/y');
$nom = $_POST['user'];
$infos = $_POST['infos'];
$result = mysql_query("INSERT INTO bands_pics (id,band,url,date,infos,valide,user) VALUES ('NULL', '$band', '$imagename','$vraidate','$infos','0','$nom')");
}
}
?>
123