Uploading pictures error message

A

Anonymous

Guest
Hi,

I run an engraving website and would like people to be able to upload pics so that I will be able to engrave them. I've got the code put together but everytime I check to see if it will work I get this error message:

Warning: chmod(): Operation not permitted in /home/classic/public_html/upload.php on line 25
Could not set the correct permissions

I'm new to php so I'm guessing it's probably a simple error that I made.

Here's my code:

<?php
### SET THESE VARIABLES ###
$to_address = "orders@classicengraving.org"; # Where you want the email sent
$subject = "File Uploaded!"; # What you want the email subject to say
$new_page = "next.php"; # Where you want the user to be taken once the file has been uploaded
### END CONFIGURATION ###
if( !empty( $_FILES['picture']['name'] ) ){
if( !file_exists( $_SERVER['DOCUMENT_ROOT']."/uploads/pictures/" ) ){
mkdir( $_SERVER['DOCUMENT_ROOT']."/uploads/pictures/", 0755 ) or
die('unable to create the directory!');
}
$valid = 0;
$f_type = $_FILES['picture']['type'];
switch( $f_type ){
case ( ( $f_type == "image/jpeg" ) or ( $f_type == "image/pjpeg" ) )
: $valid = 1; break;
case ( $f_type == "image/png" ) : $valid = 1; break;
case ( $f_type == "image/gif" ) : $valid = 1; break;
case ( $f_type == "image/wbmp" ) : $valid = 1; break;
default : $valid = 0; break;
}
if( $valid == 0 ){
die( "Not a valid filetype!" );
}
chmod( $_SERVER['DOCUMENT_ROOT']."/uploads/pictures/", 0777 ) or
die('Could not set the correct permissions');
move_uploaded_file( $_FILES['picture']['tmp_name'],
$_SERVER['DOCUMENT_ROOT']."/uploads/pictures/".$_FILES['pictures']['name'] ) or
die('Could not move the file!');
chmod( $_SERVER['DOCUMENT_ROOT']."/uploads/pictures/", 0755 ) or
die('Could not reset the correct permissions');
$msg = 'File Uploaded!\r';
$msg.= 'File was uploaded by '.$_SERVER["REMOTE_ADDR"].' at
'.date('m/d/y [G]').'\r';
$msg.= 'File:
http://'.$_SERVER["HTTP_HOST"].'/uploads/pictures/'.$_FILES['picture']['name'].'\r';
$msg.= 'Do not reply to this message.';
$headers = "Content-Type:text\r\n";
$headers.= "From: uploads[at]".$_SERVER['HTTP_HOST']."\r\n";
$headers.= "Reply-To: blackhole[at]".$_SERVER['HTTP_HOST']."\r\n";
mail( $to_address, $subject, $msg, $headers ) or die('Could not send
email');
if( !headers_sent() ){
header( "Location:".$new_page );
exit();
} else{
echo('<meta http-equiv="refresh" content="0;url='.$new_page.'" />');
}
} else{
die( 'No file was selected for upload!' );
}
?>
 
why are you chmoding
you do that manually for a directory..
and only that directory you allow uploads.
 
Someone gave this code to me and said it would probably work.......
Should I just take out the whole chmod block?
 
moonlit said:
Someone gave this code to me and said it would probably work.......
Should I just take out the whole chmod block?
set behind each chmod @ and you see your message
 
Is this what you mean?

@ chmod( $_SERVER['DOCUMENT_ROOT']."/uploads/pictures/", 0777 ) or
die('Could not set the correct permissions');
move_uploaded_file( $_FILES['picture']['tmp_name'],
$_SERVER['DOCUMENT_ROOT']."/uploads/pictures/".$_FILES['pictures']['name'] ) or
die('Could not move the file!');
@ chmod( $_SERVER['DOCUMENT_ROOT']."/uploads/pictures/", 0755 ) or
die('Could not reset the correct permissions');

Cause I did that and I still get the error message "could not set the correct permissions".
 
It's mean what PHP cannot run correct this function:
@chmod( $_SERVER['DOCUMENT_ROOT']."/uploads/pictures/", 0777 ) or
die('Could not set the correct permissions');

1 are you sure what folder exists?
2 if folder exists login in PuTTY and see original folder permission.
3 if 1 and 2 is ok ask about permission at the administrators....

more problef from ungly hands of admin.... sorry but this true....
but some time all what folder you create give other permission it for security....

PS
if( !file_exists( $_SERVER['DOCUMENT_ROOT']."/uploads/pictures/" ) ){
as I know file_exist if function for files not for folders....
 
Back
Top