sjslovechild Posted March 26, 2008 Share Posted March 26, 2008 I'm using PHP Version 4.4.3 on a Windows NT WEBHOST 5.2 build 3790 I'm having a odd problem with uploading image gallery pics to the server. I can upload the files with my php script and see the files via a FTP program. But the upload files have no file permissions. The server admin tells me that it is the Anonymous User permissions are not begin assigned. The code I'm using is below. Is there anything in the code that I'm missing? thanks. <?php // define a constant for the maximum upload size define ('MAX_FILE_SIZE', 51200); if (array_key_exists('upload', $_POST)) { // define constant for upload folder define('UPLOAD_DIR', '/path/to/picture/directory/pics/'); // replace any spaces in original filename with underscores // at the same time, assign to a simpler variable $file = str_replace(' ', '_', $_FILES['image']['name']); // convert the maximum size to KB $max = number_format(MAX_FILE_SIZE/1024, 1).'KB'; // create an array of permitted MIME types $permitted = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png'); // begin by assuming the file is unacceptable $sizeOK = false; $typeOK = false; // check that file is within the permitted size if ($_FILES['image']['size'] > 0 && $_FILES['image']['size'] <= MAX_FILE_SIZE) { $sizeOK = true; } // check that file is of an permitted MIME type foreach ($permitted as $type) { if ($type == $_FILES['image']['type']) { $typeOK = true; break; } } if ($sizeOK && $typeOK) { switch($_FILES['image']['error']) { case 0: // move the file to the upload folder and rename it $success = move_uploaded_file($_FILES['image']['tmp_name'], UPLOAD_DIR.$file); if ($success) { $result = "$file uploaded successfully"; } else { $result = "Error uploading $file. Please try again."; } break; case 3: $result = "Error uploading $file. Please try again."; default: $result = "System error uploading $file. Contact webmaster."; } } elseif ($_FILES['image']['error'] == 4) { $result = 'No file selected'; } else { $result = "$file cannot be uploaded. Maximum size: $max. Acceptable file types: gif, jpg, png."; } } ?> Link to comment https://forums.phpfreaks.com/topic/97978-file-permissions-not-assigned-when-uploading-images-to-server/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.