gdfhghjdfghgfhf Posted May 18, 2008 Share Posted May 18, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/106131-desesperatly-need-help-to-fix-this-upload-script/ Share on other sites More sharing options...
gdfhghjdfghgfhf Posted May 18, 2008 Author Share Posted May 18, 2008 bump Quote Link to comment https://forums.phpfreaks.com/topic/106131-desesperatly-need-help-to-fix-this-upload-script/#findComment-544150 Share on other sites More sharing options...
gdfhghjdfghgfhf Posted May 18, 2008 Author Share Posted May 18, 2008 Quote Link to comment https://forums.phpfreaks.com/topic/106131-desesperatly-need-help-to-fix-this-upload-script/#findComment-544291 Share on other sites More sharing options...
MadTechie Posted May 18, 2008 Share Posted May 18, 2008 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... If everyone as read access to the uploaded file then you can create the thumbnail and do whatever you want to it, so Daniel0 could still be right, but as you have posted this problem before why start a new thread ? it just means we have less info now! Quote Link to comment https://forums.phpfreaks.com/topic/106131-desesperatly-need-help-to-fix-this-upload-script/#findComment-544317 Share on other sites More sharing options...
gdfhghjdfghgfhf Posted May 19, 2008 Author Share Posted May 19, 2008 here is the old thread if this can help... http://www.phpfreaks.com/forums/index.php/topic,195388.msg880039.html#msg880039 Quote Link to comment https://forums.phpfreaks.com/topic/106131-desesperatly-need-help-to-fix-this-upload-script/#findComment-544565 Share on other sites More sharing options...
MadTechie Posted May 19, 2008 Share Posted May 19, 2008 but this wouldnt explain why i have no problem with my thumbs the script creates 2 images: the file itself, and a resized image (thumb) if it would be a problem of permissions, isn't both images supposed to have the same problem? i have explained that if the permission are wrong on the main image that doesn't mean the permission are the same on the thumbnail image, loadup the site control panel (manager) or ftp and check the permissions from their also check the folders permissions (if its different from the thumbnails) Quote Link to comment https://forums.phpfreaks.com/topic/106131-desesperatly-need-help-to-fix-this-upload-script/#findComment-544692 Share on other sites More sharing options...
gdfhghjdfghgfhf Posted May 19, 2008 Author Share Posted May 19, 2008 i have explained that if the permission are wrong on the main image that doesn't mean the permission are the same on the thumbnail image, loadup the site control panel (manager) or ftp and check the permissions from their also check the folders permissions (if its different from the thumbnails) - the main image and the thumbnail are created from the same php script - the thumbnail and the main image are stored on the same folder - the thumbnail and the main image have the same permissions if i take my script, and host it on a different server, there is no problem at all. i don't even have to change the permissions Quote Link to comment https://forums.phpfreaks.com/topic/106131-desesperatly-need-help-to-fix-this-upload-script/#findComment-545145 Share on other sites More sharing options...
MadTechie Posted May 19, 2008 Share Posted May 19, 2008 if i take my script, and host it on a different server, there is no problem at all. i don't even have to change the permissions Speak to the Host provider as if the script works then it problem with their permissions, i have done tons of scripts with file access and never had these problems, with any host. so theirs something else going Quote Link to comment https://forums.phpfreaks.com/topic/106131-desesperatly-need-help-to-fix-this-upload-script/#findComment-545261 Share on other sites More sharing options...
gdfhghjdfghgfhf Posted May 19, 2008 Author Share Posted May 19, 2008 if i take my script, and host it on a different server, there is no problem at all. i don't even have to change the permissions Speak to the Host provider as if the script works then it problem with their permissions, i have done tons of scripts with file access and never had these problems, with any host. so theirs something else going i already tryed that, but it is very hard to get support from my host... i have to find another work around to fix this If the thumbnail file is working then there must be a way to make it work.... theorically if i can manage to make the image the same way the thumbnail file is made then it should be working.... even if the image is resized a bit i dont really care... Quote Link to comment https://forums.phpfreaks.com/topic/106131-desesperatly-need-help-to-fix-this-upload-script/#findComment-545308 Share on other sites More sharing options...
MadTechie Posted May 20, 2008 Share Posted May 20, 2008 From what your saying, a script creates 2 files in the same way, but then you loss write access to one of the files, but it works on the another host.. so to sum up, the script is fine and you insist its not a permission problem.. then your only option is to speak to the host, as its not a php problem. Personally i think its a permission problem Quote Link to comment https://forums.phpfreaks.com/topic/106131-desesperatly-need-help-to-fix-this-upload-script/#findComment-545510 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.