Jump to content

Archived

This topic is now archived and is closed to further replies.

skatermike21988

MAJOR IMAGE UPLOAD PROBLEM!!

Recommended Posts

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:
[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>";

[/code]

Thanks in advance for any help

Share this post


Link to post
Share on other sites
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.com/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";
}

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.