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!' );
}
?>
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!' );
}
?>