当前位置: 首页>>代码示例>>PHP>>正文


PHP UploadFile::unlink_file方法代码示例

本文整理汇总了PHP中UploadFile::unlink_file方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadFile::unlink_file方法的具体用法?PHP UploadFile::unlink_file怎么用?PHP UploadFile::unlink_file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UploadFile的用法示例。


在下文中一共展示了UploadFile::unlink_file方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: UploadFile

 function action_save()
 {
     require_once 'include/upload_file.php';
     $GLOBALS['log']->debug('PERFORMING NOTES SAVE');
     $upload_file = new UploadFile('uploadfile');
     $do_final_move = 0;
     if (isset($_FILES['uploadfile']) && $upload_file->confirm_upload()) {
         if (!empty($this->bean->id) && !empty($_REQUEST['old_filename'])) {
             $upload_file->unlink_file($this->bean->id, $_REQUEST['old_filename']);
         }
         $this->bean->filename = $upload_file->get_stored_file_name();
         $this->bean->file_mime_type = $upload_file->mime_type;
         $do_final_move = 1;
     } else {
         if (isset($_REQUEST['old_filename'])) {
             $this->bean->filename = $_REQUEST['old_filename'];
         }
     }
     $this->bean->save();
     if ($do_final_move) {
         $upload_file->final_move($this->bean->id);
     } else {
         if (!empty($_REQUEST['old_id'])) {
             $upload_file->duplicate_file($_REQUEST['old_id'], $this->bean->id, $this->bean->filename);
         }
     }
 }
开发者ID:klr2003,项目名称:sourceread,代码行数:27,代码来源:controller.php

示例2: UploadFile

 function action_save()
 {
     require_once 'include/upload_file.php';
     $GLOBALS['log']->debug('PERFORMING NOTES SAVE');
     $upload_file = new UploadFile('uploadfile');
     $do_final_move = 0;
     if (isset($_FILES['uploadfile']) && $upload_file->confirm_upload()) {
         if (!empty($this->bean->id) && !empty($_REQUEST['old_filename'])) {
             $upload_file->unlink_file($this->bean->id, $_REQUEST['old_filename']);
         }
         $this->bean->filename = $upload_file->get_stored_file_name();
         $this->bean->file_mime_type = $upload_file->mime_type;
         $do_final_move = 1;
     } else {
         if (isset($_REQUEST['old_filename'])) {
             $this->bean->filename = $_REQUEST['old_filename'];
         }
     }
     $check_notify = false;
     if (!empty($_POST['assigned_user_id']) && (empty($this->bean->fetched_row) || $this->bean->fetched_row['assigned_user_id'] != $_POST['assigned_user_id']) && $_POST['assigned_user_id'] != $GLOBALS['current_user']->id) {
         $check_notify = true;
     }
     $this->bean->save($check_notify);
     if ($do_final_move) {
         $upload_file->final_move($this->bean->id);
     } else {
         if (!empty($_REQUEST['old_id'])) {
             $upload_file->duplicate_file($_REQUEST['old_id'], $this->bean->id, $this->bean->filename);
         }
     }
 }
开发者ID:aldridged,项目名称:gtg-sugar,代码行数:31,代码来源:controller.php

示例3: save

 public function save(&$bean, $params, $field, $vardef, $prefix = '')
 {
     $fakeDisplayParams = array();
     $this->fillInOptions($vardef, $fakeDisplayParams);
     require_once 'include/upload_file.php';
     $upload_file = new UploadFile($prefix . $field . '_file');
     //remove file
     if (isset($_REQUEST['remove_file_' . $field]) && $params['remove_file_' . $field] == 1) {
         $upload_file->unlink_file($bean->{$field});
         $bean->{$field} = "";
     }
     $move = false;
     if (isset($_FILES[$prefix . $field . '_file']) && $upload_file->confirm_upload()) {
         if ($this->verify_image($upload_file)) {
             $bean->{$field} = $upload_file->get_stored_file_name();
             $move = true;
         } else {
             //not valid image.
             $GLOBALS['log']->fatal("Image Field : Not a Valid Image.");
             $temp = $vardef['vname'];
             $temp = translate($temp, $bean->module_name);
             SugarApplication::appendErrorMessage($temp . " Field :  Not a valid image format.");
         }
     }
     if (empty($bean->id)) {
         $bean->id = create_guid();
         $bean->new_with_id = true;
     }
     if ($move) {
         $upload_file->final_move($bean->id . '_' . $field);
         //BEAN ID IS THE FILE NAME IN THE INSTANCE.
         $upload_file->upload_doc($bean, $bean->id, $params[$prefix . $vardef['docType']], $bean->{$field}, $upload_file->mime_type);
     } else {
         if (!empty($old_id)) {
             // It's a duplicate, I think
             if (empty($params[$prefix . $vardef['docUrl']])) {
                 $upload_file->duplicate_file($old_id, $bean->id, $bean->{$field});
             } else {
                 $docType = $vardef['docType'];
                 $bean->{$docType} = $params[$prefix . $field . '_old_doctype'];
             }
         } else {
             if (!empty($params[$prefix . $field . '_remoteName'])) {
                 // We aren't moving, we might need to do some remote linking
                 $displayParams = array();
                 $this->fillInOptions($vardef, $displayParams);
                 if (isset($params[$prefix . $vardef['docId']]) && !empty($params[$prefix . $vardef['docId']]) && isset($params[$prefix . $vardef['docType']]) && !empty($params[$prefix . $vardef['docType']])) {
                     $bean->{$field} = $params[$prefix . $field . '_remoteName'];
                     require_once 'include/utils/file_utils.php';
                     $extension = get_file_extension($bean->{$field});
                     if (!empty($extension)) {
                         $bean->file_ext = $extension;
                         $bean->file_mime_type = get_mime_content_type_from_filename($bean->{$field});
                     }
                 }
             }
         }
     }
 }
开发者ID:MexinaD,项目名称:SuiteCRM,代码行数:59,代码来源:SugarFieldImage.php

示例4: UploadFile

 function action_save()
 {
     require_once 'include/upload_file.php';
     // CCL - Bugs 41103 and 43751.  41103 address the issue where the parent_id is set, but
     // the relate_id field overrides the relationship.  43751 fixes the problem where the relate_id and
     // parent_id are the same value (in which case it should just use relate_id) by adding the != check
     if (!empty($_REQUEST['relate_id']) && !empty($_REQUEST['parent_id']) && $_REQUEST['relate_id'] != $_REQUEST['parent_id']) {
         $_REQUEST['relate_id'] = false;
     }
     $GLOBALS['log']->debug('PERFORMING NOTES SAVE');
     $upload_file = new UploadFile('uploadfile');
     $do_final_move = 0;
     if (isset($_FILES['uploadfile']) && $upload_file->confirm_upload()) {
         if (!empty($this->bean->id) && !empty($_REQUEST['old_filename'])) {
             $upload_file->unlink_file($this->bean->id, $_REQUEST['old_filename']);
         }
         $this->bean->filename = $upload_file->get_stored_file_name();
         $this->bean->file_mime_type = $upload_file->mime_type;
         $do_final_move = 1;
     } else {
         if (isset($_REQUEST['old_filename'])) {
             $this->bean->filename = $_REQUEST['old_filename'];
         }
     }
     $check_notify = false;
     if (!empty($_POST['assigned_user_id']) && (empty($this->bean->fetched_row) || $this->bean->fetched_row['assigned_user_id'] != $_POST['assigned_user_id']) && $_POST['assigned_user_id'] != $GLOBALS['current_user']->id) {
         $check_notify = true;
     }
     $this->bean->save($check_notify);
     if ($do_final_move) {
         $upload_file->final_move($this->bean->id);
     } else {
         if (!empty($_REQUEST['old_id'])) {
             $upload_file->duplicate_file($_REQUEST['old_id'], $this->bean->id, $this->bean->filename);
         }
     }
 }
开发者ID:omusico,项目名称:sugar_work,代码行数:37,代码来源:controller.php

示例5: save

 public function save(&$bean, $params, $field, $properties, $prefix = '')
 {
     require_once 'include/upload_file.php';
     $upload_file = new UploadFile($prefix . $field);
     //remove file
     if (isset($_REQUEST['remove_file_' . $field]) && $_REQUEST['remove_file_' . $field] == 1) {
         $upload_file->unlink_file($bean->{$field});
         $bean->{$field} = "";
     }
     $move = false;
     if (isset($_FILES[$prefix . $field]) && $upload_file->confirm_upload()) {
         $bean->{$field} = $upload_file->get_stored_file_name();
         $bean->file_mime_type = $upload_file->mime_type;
         $bean->file_ext = $upload_file->file_ext;
         $move = true;
     }
     if ($move) {
         if (empty($bean->id)) {
             $bean->id = create_guid();
             $bean->new_with_id = true;
         }
         $upload_file->final_move($bean->id);
     }
 }
开发者ID:aldridged,项目名称:gtg-sugar,代码行数:24,代码来源:SugarFieldFile.php

示例6: mark_relationships_deleted

 /**
  * mark_relationships_deleted
  *
  * Override method from SugarBean to handle deleting relationships associated with a Document.  This method will
  * remove DocumentRevision relationships and then optionally delete Contracts depending on the version.
  *
  * @param $id String The record id of the Document instance
  */
 function mark_relationships_deleted($id)
 {
     $this->load_relationships('revisions');
     $revisions = $this->get_linked_beans('revisions', 'DocumentRevision');
     if (!empty($revisions) && is_array($revisions)) {
         foreach ($revisions as $key => $version) {
             UploadFile::unlink_file($version->id, $version->filename);
             //mark the version deleted.
             $version->mark_deleted($version->id);
         }
     }
 }
开发者ID:omusico,项目名称:SelkirkCRM,代码行数:20,代码来源:Document.php

示例7: preprocess_fields_on_save

 function preprocess_fields_on_save()
 {
     parent::preprocess_fields_on_save();
     require_once 'include/upload_file.php';
     $upload_file = new UploadFile("picture");
     //remove file
     if (isset($_REQUEST['remove_imagefile_picture']) && $_REQUEST['remove_imagefile_picture'] == 1) {
         UploadFile::unlink_file($this->picture);
         $this->picture = "";
     }
     //uploadfile
     if (isset($_FILES['picture'])) {
         //confirm only image file type can be uploaded
         $imgType = array('image/gif', 'image/png', 'image/bmp', 'image/jpeg', 'image/jpg', 'image/pjpeg');
         if (in_array($_FILES['picture']["type"], $imgType)) {
             if ($upload_file->confirm_upload()) {
                 $this->picture = create_guid();
                 $upload_file->final_move($this->picture);
             }
         }
     }
 }
开发者ID:jglaine,项目名称:sugar761-ent,代码行数:22,代码来源:Employee.php

示例8: sugar_die

    sugar_die($mod_strings['ERR_DELETE_RECORD']);
}
$focus = BeanFactory::getBean('Documents', $_REQUEST['record']);
if (!$focus->ACLAccess('Delete')) {
    ACLController::displayNoAccess(true);
    sugar_cleanup(true);
}
if (isset($_REQUEST['object']) && ($_REQUEST['object'] = "documentrevision")) {
    //delete document revision.
    $focus = BeanFactory::getBean('DocumentRevisions');
    UploadFile::unlink_file($_REQUEST['revision_id'], $_REQUEST['filename']);
} else {
    //delete document and its revisions.
    $focus = BeanFactory::getBean('Documents', $_REQUEST['record']);
    $focus->load_relationships('revisions');
    $revisions = $focus->get_linked_beans('revisions', 'DocumentRevision');
    if (!empty($revisions) && is_array($revisions)) {
        foreach ($revisions as $key => $thisversion) {
            UploadFile::unlink_file($thisversion->id, $thisversion->filename);
            //mark the version deleted.
            $thisversion->mark_deleted($thisversion->id);
        }
    }
    //Remove the contracts relationships
    $focus->load_relationship('contracts');
    if (!empty($focus->contracts)) {
        $focus->contracts->delete($focus->id);
    }
}
$focus->mark_deleted($_REQUEST['record']);
header("Location: index.php?module=" . $_REQUEST['return_module'] . "&action=" . $_REQUEST['return_action'] . "&record=" . $_REQUEST['return_id']);
开发者ID:jglaine,项目名称:sugar761-ent,代码行数:31,代码来源:Delete.php

示例9: ZuckerReport

<?php

require_once 'include/formbase.php';
require_once 'include/upload_file.php';
require_once 'modules/ZuckerReports/ZuckerReport.php';
if (isset($_REQUEST['record'])) {
    $focus = new ZuckerReport();
    $focus->retrieve($_REQUEST['record']);
    UploadFile::unlink_file($focus->id, $focus->filename);
    $focus->mark_deleted($_REQUEST['record']);
}
header("Location: index.php?module=" . $_REQUEST['return_module'] . "&action=" . $_REQUEST['return_action'] . "&record=" . $_REQUEST['return_id']);
开发者ID:aldridged,项目名称:gtg-sugar,代码行数:12,代码来源:ReportDelete.php

示例10: save

 public function save(&$bean, $params, $field, $vardef, $prefix = '')
 {
     $fakeDisplayParams = array();
     $this->fillInOptions($vardef, $fakeDisplayParams);
     require_once 'include/upload_file.php';
     $upload_file = new UploadFile($prefix . $field . '_file');
     //remove file
     if (isset($_REQUEST['remove_file_' . $field]) && $params['remove_file_' . $field] == 1) {
         $upload_file->unlink_file($bean->{$field});
         $bean->{$field} = "";
     }
     $move = false;
     if (isset($_FILES[$prefix . $field . '_file']) && $upload_file->confirm_upload()) {
         $bean->{$field} = $upload_file->get_stored_file_name();
         $bean->file_mime_type = $upload_file->mime_type;
         $bean->file_ext = $upload_file->file_ext;
         $move = true;
     }
     if (!empty($params['isDuplicate']) && $params['isDuplicate'] == 'true') {
         // This way of detecting duplicates is used in Notes
         $old_id = $params['relate_id'];
     }
     if (!empty($params['duplicateSave']) && !empty($params['duplicateId'])) {
         // It's a duplicate
         $old_id = $params['duplicateId'];
     }
     // Backwards compatibility for fields that still use customCode to handle the file uploads
     if (!$move && empty($old_id) && isset($_FILES['uploadfile'])) {
         $upload_file = new UploadFile('uploadfile');
         if ($upload_file->confirm_upload()) {
             $bean->{$field} = $upload_file->get_stored_file_name();
             $bean->file_mime_type = $upload_file->mime_type;
             $bean->file_ext = $upload_file->file_ext;
             $move = true;
         }
     } else {
         if (!$move && !empty($old_id) && isset($_REQUEST['uploadfile']) && !isset($_REQUEST[$prefix . $field . '_file'])) {
             // I think we are duplicating a backwards compatibility module.
             $upload_file = new UploadFile('uploadfile');
         }
     }
     if (empty($bean->id)) {
         $bean->id = create_guid();
         $bean->new_with_id = true;
     }
     if ($move) {
         $upload_file->final_move($bean->id);
         $upload_file->upload_doc($bean, $bean->id, $params[$prefix . $vardef['docType']], $bean->{$field}, $upload_file->mime_type);
     } else {
         if (!empty($old_id)) {
             // It's a duplicate, I think
             if (empty($params[$prefix . $vardef['docUrl']])) {
                 $upload_file->duplicate_file($old_id, $bean->id, $bean->{$field});
             } else {
                 $docType = $vardef['docType'];
                 $bean->{$docType} = $params[$prefix . $field . '_old_doctype'];
             }
         } else {
             if (!empty($params[$prefix . $field . '_remoteName'])) {
                 // We aren't moving, we might need to do some remote linking
                 $displayParams = array();
                 $this->fillInOptions($vardef, $displayParams);
                 if (isset($params[$prefix . $vardef['docId']]) && !empty($params[$prefix . $vardef['docId']]) && isset($params[$prefix . $vardef['docType']]) && !empty($params[$prefix . $vardef['docType']])) {
                     $bean->{$field} = $params[$prefix . $field . '_remoteName'];
                     require_once 'include/utils/file_utils.php';
                     $extension = get_file_extension($bean->{$field});
                     if (!empty($extension)) {
                         $bean->file_ext = $extension;
                         $bean->file_mime_type = get_mime_content_type_from_filename($bean->{$field});
                     }
                 }
             }
         }
     }
     if ($vardef['allowEapm'] == true && empty($bean->{$field})) {
         $GLOBALS['log']->info("The {$field} is empty, clearing out the lot");
         // Looks like we are emptying this out
         $clearFields = array('docId', 'docType', 'docUrl', 'docDirectUrl');
         foreach ($clearFields as $clearMe) {
             if (!isset($vardef[$clearMe])) {
                 continue;
             }
             $clearField = $vardef[$clearMe];
             $bean->{$clearField} = '';
         }
     }
 }
开发者ID:jgera,项目名称:sugarcrm_dev,代码行数:87,代码来源:SugarFieldFile.php

示例11: sugar_cleanup

if (!$focus->ACLAccess('Delete')) {
    ACLController::displayNoAccess(true);
    sugar_cleanup(true);
}
//Retrieve all related kbdocument revisions.
$kbdocrevs = KBDocument::get_kbdocument_revisions($_REQUEST['record']);
//Loop through kbdocument revisions and delete one by one.
if (!empty($kbdocrevs) && is_array($kbdocrevs)) {
    foreach ($kbdocrevs as $key => $thiskbid) {
        $thiskbversion = BeanFactory::getBean('KBDocumentRevisions', $thiskbid);
        //Check for related documentrevision and delete.
        if ($thiskbversion->document_revision_id != null) {
            $docrev_id = $thiskbversion->document_revision_id;
            $thisdocrev = BeanFactory::getBean('DocumentRevisions', $docrev_id);
            UploadFile::unlink_file($docrev_id, $thisdocrev->filename);
            UploadFile::unlink_file($docrev_id);
            //mark version deleted
            $thisdocrev->mark_deleted($thisdocrev->id);
        }
        //Also check for related kbcontent and delete.
        if ($thiskbversion->kbcontent_id != null) {
            BeanFactory::deleteBean('KBContents', $thiskbversion->kbcontent_id);
        }
        //Finally delete the kbdocument revision.
        $thiskbversion->mark_deleted($thiskbversion->id);
    }
}
//delete kbdocuments_kbtags
$deleted = 1;
$q = 'UPDATE kbdocuments_kbtags SET deleted = ' . $deleted . ' WHERE kbdocument_id = \'' . $_REQUEST['record'] . '\'';
$focus->db->query($q);
开发者ID:jglaine,项目名称:sugar761-ent,代码行数:31,代码来源:Delete.php

示例12: save

 public function save($bean, $params, $field, $vardef, $prefix = '')
 {
     $fakeDisplayParams = array();
     $this->fillInOptions($vardef, $fakeDisplayParams);
     require_once 'include/upload_file.php';
     $upload_file = new UploadFile($prefix . $field . '_file');
     //remove file
     if (isset($_REQUEST['remove_file_' . $field]) && $params['remove_file_' . $field] == 1) {
         $upload_file->unlink_file($bean->{$field});
         $bean->{$field} = "";
     }
     $move = false;
     // In case of failure midway, we need to reset the values of the bean
     $originalvals = array('value' => $bean->{$field});
     // Bug 57400 - Some beans with a filename field type do NOT have file_mime_type
     // or file_ext. In the case of Documents, for example, this happens to be
     // the case, since the DocumentRevisions bean is where these fields are found.
     if (isset($bean->file_mime_type)) {
         $originalvals['mime'] = $bean->file_mime_type;
     }
     if (isset($bean->file_ext)) {
         $originalvals['ext'] = $bean->file_ext;
     }
     if (isset($_FILES[$prefix . $field . '_file']) && $upload_file->confirm_upload()) {
         // in order to avoid any discrepancies of MIME type with the download code,
         // call the same MIME function instead of using the uploaded file's mime type property.
         $mimeType = get_file_mime_type($upload_file->get_temp_file_location(), 'application/octet-stream');
         //verify the image
         if (in_array($mimeType, self::$imageFileMimeTypes) && !verify_image_file($upload_file->get_temp_file_location())) {
             $this->error = string_format($GLOBALS['app_strings']['LBL_UPLOAD_IMAGE_FILE_NOT_SUPPORTED'], array($upload_file->file_ext));
             return;
         }
         $bean->{$field} = $upload_file->get_stored_file_name();
         $bean->file_mime_type = $upload_file->mime_type;
         $bean->file_ext = $upload_file->file_ext;
         $move = true;
     } else {
         $this->error = $upload_file->getErrorMessage();
     }
     if (!empty($params['isDuplicate']) && $params['isDuplicate'] == 'true') {
         // This way of detecting duplicates is used in Notes
         $old_id = $params['relate_id'];
     }
     if (!empty($params['duplicateSave']) && !empty($params['duplicateId'])) {
         // It's a duplicate
         $old_id = $params['duplicateId'];
     }
     // case when we should copy one file to another using merge-duplicate view
     // $params[$field . '_duplicateBeanId'] contains id of bean from
     // which we should copy file.
     if (!empty($params[$field . '_duplicateBeanId'])) {
         $duplicateModuleId = $params[$field . '_duplicateBeanId'];
     }
     // Backwards compatibility for fields that still use customCode to handle the file uploads
     if (!$move && empty($old_id) && isset($_FILES['uploadfile'])) {
         $upload_file = new UploadFile('uploadfile');
         if ($upload_file->confirm_upload()) {
             $bean->{$field} = $upload_file->get_stored_file_name();
             $bean->file_mime_type = $upload_file->mime_type;
             $bean->file_ext = $upload_file->file_ext;
             $move = true;
         } else {
             $this->error = $upload_file->getErrorMessage();
         }
     } elseif (!$move && !empty($old_id) && isset($_REQUEST['uploadfile']) && !isset($_REQUEST[$prefix . $field . '_file'])) {
         // I think we are duplicating a backwards compatibility module.
         $upload_file = new UploadFile('uploadfile');
     }
     if (empty($bean->id)) {
         $bean->id = create_guid();
         $bean->new_with_id = true;
     }
     if ($move) {
         $temp = !empty($params['temp']);
         // Added checking of final move to capture errors that might occur
         if ($upload_file->final_move($bean->id, $temp)) {
             if (!$temp) {
                 // This fixes an undefined index warning being thrown
                 $docType = isset($vardef['docType']) && isset($params[$prefix . $vardef['docType']]) ? $params[$prefix . $vardef['docType']] : null;
                 $upload_file->upload_doc($bean, $bean->id, $docType, $bean->{$field}, $upload_file->mime_type);
             }
         } else {
             // Reset the bean back to original, but only if we had set them.
             $bean->{$field} = $originalvals['value'];
             // See comments for these properties above in regards to Bug 57400
             if (isset($originalvals['mime'])) {
                 $bean->file_mime_type = $originalvals['mime'];
             }
             if (isset($originalvals['ext'])) {
                 $bean->file_ext = $originalvals['ext'];
             }
             // Report the error
             $this->error = $upload_file->getErrorMessage();
         }
     } elseif (!empty($old_id)) {
         // It's a duplicate, I think
         if (empty($vardef['docUrl']) || empty($params[$prefix . $vardef['docUrl']])) {
             $upload_file->duplicate_file($old_id, $bean->id, $bean->{$field});
         } else {
             $docType = $vardef['docType'];
//.........这里部分代码省略.........
开发者ID:jglaine,项目名称:sugar761-ent,代码行数:101,代码来源:SugarFieldFile.php

示例13: save

 public function save(&$bean, $params, $field, $properties, $prefix = '')
 {
     require_once 'include/upload_file.php';
     $upload_file = new UploadFile($field);
     //remove file
     if (isset($_REQUEST['remove_imagefile_' . $field]) && $_REQUEST['remove_imagefile_' . $field] == 1) {
         $upload_file->unlink_file($bean->{$field});
         $bean->{$field} = "";
     }
     //uploadfile
     if (isset($_FILES[$field])) {
         //confirm only image file type can be uploaded
         if (verify_image_file($_FILES[$field]['tmp_name'])) {
             if ($upload_file->confirm_upload()) {
                 // for saveTempImage API
                 if (isset($params['temp']) && $params['temp'] === true) {
                     // Create the new field value
                     $bean->{$field} = create_guid();
                     // Move to temporary folder
                     if (!$upload_file->final_move($bean->{$field}, true)) {
                         // If this was a fail, reset the bean field to original
                         $this->error = $upload_file->getErrorMessage();
                     }
                 } else {
                     // Capture the old value in case of error
                     $oldvalue = $bean->{$field};
                     // Create the new field value
                     $bean->{$field} = create_guid();
                     // Add checking for actual file move for reporting to consumers
                     if (!$upload_file->final_move($bean->{$field})) {
                         // If this was a fail, reset the bean field to original
                         $bean->{$field} = $oldvalue;
                         $this->error = $upload_file->getErrorMessage();
                     }
                 }
             } else {
                 // Added error reporting
                 $this->error = $upload_file->getErrorMessage();
             }
         } else {
             $imgInfo = getimagesize($_FILES[$field]['tmp_name']);
             // if file is image then this image is no longer supported.
             if (false !== $imgInfo) {
                 $ext = end(explode('.', $_FILES[$field]['name']));
                 $this->error = string_format($GLOBALS['app_strings']['LBL_UPLOAD_IMAGE_FILE_NOT_SUPPORTED'], array($ext));
             } else {
                 $this->error = $GLOBALS['app_strings']["LBL_UPLOAD_IMAGE_FILE_INVALID"];
             }
         }
     }
     //Check if we have the duplicate value set and use it if $bean->$field is empty
     if (empty($bean->{$field}) && !empty($_REQUEST[$field . '_duplicate'])) {
         $bean->{$field} = $_REQUEST[$field . '_duplicate'];
     }
     // case when we should copy one file to another using merge-duplicate view
     // $params[$field . '_duplicateBeanId'] contains id of bean from
     // which we should copy file.
     if (!empty($params[$field]) && !empty($params[$field . '_duplicateBeanId'])) {
         $bean->{$field} = create_guid();
         $upload_file->duplicate_file($params[$field], $bean->{$field});
     }
 }
开发者ID:jglaine,项目名称:sugar761-ent,代码行数:62,代码来源:SugarFieldImage.php

示例14: handleSave

 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'include/formbase.php';
     require_once 'include/upload_file.php';
     $focus = new Note();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     if (empty($focus->name)) {
         return null;
     }
     if (!isset($_REQUEST['date_due_flag'])) {
         $focus->date_due_flag = 0;
     }
     if (!isset($_REQUEST['portal_flag'])) {
         $focus->portal_flag = '0';
     }
     $upload_file = new UploadFile('uploadfile');
     $do_final_move = 0;
     if (isset($_FILES['uploadfile']) && $upload_file->confirm_upload()) {
         if (!empty($focus->id) && !empty($_REQUEST['old_filename'])) {
             $upload_file->unlink_file($focus->id, $_REQUEST['old_filename']);
         }
         $focus->filename = $upload_file->get_stored_file_name();
         $focus->file_mime_type = $upload_file->mime_type;
         $do_final_move = 1;
     } else {
         if (isset($_REQUEST['old_filename'])) {
             $focus->filename = $_REQUEST['old_filename'];
         }
     }
     $return_id = $focus->save();
     if ($do_final_move) {
         $upload_file->final_move($focus->id);
     } else {
         if (!empty($_REQUEST['old_id'])) {
             $upload_file->duplicate_file($_REQUEST['old_id'], $focus->id, $focus->filename);
         }
     }
     if ($redirect) {
         $GLOBALS['log']->debug("Saved record with id of " . $return_id);
         handleRedirect($return_id, "Notes");
     } else {
         return $focus;
     }
 }
开发者ID:klr2003,项目名称:sourceread,代码行数:51,代码来源:NoteFormBase.php

示例15: removeFile

 /**
  * Removes an attachment from a record field
  *
  * @param ServiceBase $api The service base
  * @param array $args The request args
  * @return array Listing of fields for a record
  * @throws SugarApiExceptionError|SugarApiExceptionNoMethod|SugarApiExceptionRequestMethodFailure
  */
 public function removeFile($api, $args)
 {
     // Get the field
     $field = $args['field'];
     // Get the bean
     $bean = $this->loadBean($api, $args);
     // Handle ACL
     $this->verifyFieldAccess($bean, $field, 'delete');
     // Only remove if there is something to remove
     if (!empty($bean->{$field})) {
         // Get the defs for this field
         $def = $bean->field_defs[$field];
         // Only work on file or image fields
         if (isset($def['type']) && ($def['type'] == 'image' || $def['type'] == 'file')) {
             if ($def['type'] == 'file') {
                 if (method_exists($bean, 'deleteAttachment')) {
                     if (!$bean->deleteAttachment()) {
                         // @TODO Localize this exception message
                         throw new SugarApiExceptionRequestMethodFailure('Removal of attachment failed.');
                     }
                 } else {
                     // @TODO Localize this exception message
                     throw new SugarApiExceptionNoMethod('No method found to remove attachment.');
                 }
             } else {
                 require_once 'include/upload_file.php';
                 $upload = new UploadFile($field);
                 $upload->unlink_file($bean->{$field});
                 $bean->{$field} = '';
                 $bean->save();
             }
         } else {
             // @TODO Localize this exception message
             throw new SugarApiExceptionError("Unexpected field type: " . $def['type']);
         }
     }
     $list = $this->getFileList($api, $args);
     $list['record'] = $this->formatBean($api, $args, $bean);
     return $list;
 }
开发者ID:jglaine,项目名称:sugar761-ent,代码行数:48,代码来源:FileApi.php


注:本文中的UploadFile::unlink_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。