Jump to content


Photo

MAJOR IMAGE UPLOAD PROBLEM!!


  • Please log in to reply
2 replies to this topic

#1 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 24 September 2006 - 07:12 AM

Ok, i have a pretty basic image upload handler and it all works, the directory is chmod to 777 and it successfully puts the file there, but the uploaded file gets chmod to 600 not allowing it to be executed, i store the completed upload source into a database since the script is user specific, it stores in the database just fine and uploads fine, but won't display the pic until i manually chmod it to 777, why is it doing this, i've used the same code before and it has worked just fine, no all the problems.

PLEASE HELP!!!

Here is my upload code:
if ($set=='') {
$upload=$_REQUEST[upload];
?><table border=1><tr><td><center>Image Upload<form action="?upload=step1&sid=<? echo "$sid"; ?>" method="post" ENCTYPE="multipart/form-data" onsubmit"document.progress.disabled=false">
<input type="file" name="file" size="30"><br>*Files Must Be No Bigger Than 10 Megs*<br> *No Bigger Than 800 X 800 Pixels*<br>*Porn/Nudity Will Not Be Accepted And Will Result In Supsension For 15 Days*<br>*On The First Offense And Account Termination On The Second Offense*<br> <input type="submit" value="Upload!">
</form> 
<? if ($upload=='step1') {
// ==============
// Configuration
// ==============
$uploaddir = "userpics"; // Where you want the files to upload to - Important: Make sure this folders permissions is 0777!
$allowed_ext = "jpg, gif, png, JPG, GIF, PNG, JPEG, jpeg"; // These are the allowed extensions of the files that are uploaded
$max_size = "1000000"; // 50000 is the same as 50kb
$max_height = "800"; // This is in pixels - Leave this field empty if you don't want to upload images
$max_width = "800"; // This is in pixels - Leave this field empty if you don't want to upload images 
// Check Entension
$extension = pathinfo($_FILES['file']['name']);
$extension = $extension[extension];
$allowed_paths = explode(", ", $allowed_ext);
for($i = 0; $i < count($allowed_paths); $i++) {
 if ($allowed_paths[$i] == "$extension") {
 $ok = "1";
 }
}

// Check File Size
if ($ok == "1") {
if($_FILES['file']['size'] > $max_size)
{
print "<font color=red>**ERROR**<br>File size is too big!</font></td></tr><table>";
exit;
}

// Check Height & Width
if ($max_width && $max_height) {
list($width, $height, $type, $w) = getimagesize($_FILES['file']['tmp_name']);
if($width > $max_width || $height > $max_height)
{
print "<font color=red>**ERROR**<br>File height and/or width are too big!</font></td></tr><table>";
exit;
}
}
$pic_name=$_FILES['file']['name'];
// The Upload Part
$check=mysql_query("SELECT * FROM `photos` WHERE source = 'http://www.mysite.com/userpics/$pic_name'")or die(mysql_error()); 
$Numb=mysql_num_rows($check); 


if($Numb > 0) { 
echo "<br><font color=red>**ERROR**<br>Sorry That Photo Already Exists, Try Renaming.</font></td></tr><table>";
} else {
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);
}
print "<br>Congratulations your image was successfully uploaded!</td></tr><table>";
$INSERT=mysql_query("INSERT INTO `photos`(user_id,source,pic_name) VALUES 
('$id', 'http://www.mysite.com/userpics/$pic_name', '$pic_name')")or die(mysql_error()); 
}


} else {
print "<font color=red>**ERROR**<br>Incorrect file extension!</font></td></tr><table>";
}

}
echo "</table>";


Thanks in advance for any help

#2 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 25 September 2006 - 06:07 AM

any ideas???

#3 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 25 September 2006 - 06:12 AM

Well i have two solutions...
learn how to CHMODD the file when uploaded; www.php.net, and you will need:
chmod(); file_exists();

EXAMPLE:
$file_dir = "http://www.website.c...m/img/dir/priv"
if(file_exists($file_dir/$filename)){
chmod("$file_dir/$filename", 0777); // must be 0777, 777 might be incorrect.
}else{
echo "file doesn't exist";
}




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users